views:

15

answers:

1

I'd like to have some HTML like this:

<div id="div0" someAttr="0" class="shown">Some stuff</div>
<div id="div1" someAttr="1">Some stuff</div> 
<div id="div2" someAttr="2">Some stuff</div> 
<div id="div3" someAttr="3">Some stuff</div> 

And then manipulate it like this:

$('div').click(function()
   {
   if($(this).someAttr > $('div.shown').someAttr)
      doSomething();
   });

But I don't want to write bad markup. Is there an all-purpose attribute I can set?

+2  A: 

You could use the jQuery .data() method, allows you to apply data to an element without having to use attributes in an non-semantic fashion.

That said looking back at your question are you looking at generating those values from the back end or using jQuery?

http://api.jquery.com/jQuery.data/

ILMV
Nope, it's not back end, I can totally use this! Sweet!
Isaac Lubow
Awesome! Glad I could help :-)
ILMV
You don't even need jQuery, you can write `someElement.someMadeUpProperty= 3` without making it a string attribute value. These are called ‘expando’ properties and though they are not standardised, every browser implements them and indeed jQuery uses them to implement `data()`. You should just be careful to pick a name that isn't going to become a real DOM property in the future (eg. prefix the name with `_`).
bobince
Good to know bobince, I wasn't aware of this but considering Isaac is using jQuery already the extra functionality of cross browser support etc etc would make the data method favourable?
ILMV