Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing data tag from a non HTML5 browser

Tags:

html

jquery

I'm a total noob in the web arena, I've been learning jQuery lately. My concern is, will I be able to access the 'data' attribute using jQuery from my HTML if my browser does not support HTML5?

like image 587
Ragunath Jawahar Avatar asked Dec 27 '22 04:12

Ragunath Jawahar


1 Answers

Yes, you can use the data attribute and you will be able to access it with jQuery even if the browser doesn't support HTML5:

var value = $('#foo').data('value');

where you have:

<div id="foo" data-value="bar">Baz</div>

The only thing is that the data attribute is not valid if your DOCTYPE is not HTML5 => if you try to use it in HTML 4.01 Transitional for example the validator will cry but your site will work without issues.

like image 98
Darin Dimitrov Avatar answered Jan 09 '23 04:01

Darin Dimitrov