Reputation: 183
Can I use a "blank" class to identify common elements of the dom in order to perform operations with jquery? I know the tag Id and Name must be unique in the dom, but, if i need identified similar elements but not necessary with the same styling... For example, in this scenario:
<section class="custom-section identify1"></section>
<section class="custom-section identify1"></section>
<section class="custom-section identify2"></section>
<section class="custom-section identify1"></section>
<section class="custom-section identify2"></section>
<section class="custom-section identify1"></section>
In this scenario custom-section
styling the section and identifyX group similar sections...
¿is correct?
And now with jquery i can get all section with identifyX:
$(".identify1)
I know in html5 exist custom data atributte (Data-*) custom data HTML5 Can I use this tag for this functionallity?
Upvotes: 2
Views: 64
Reputation: 14863
Yes the, data attribute selected would be beetter, then setting a CSS class for you jQuery selector.
Here is an example using the data-X attribute selecotr
HTML:
<p data-test="">Hello</p>
JS:
var text = $('[data-test]').text();
alert(text);
Upvotes: 1
Reputation: 174997
Yes, it's perfectly acceptable to use classnames like that.
A class name is used to designate similar groups of elements. So that fits right in.
Upvotes: 0
Reputation: 53929
Yes you can use "dummy" class names, that don't actually have any styles defined in the CSS.
And the correct seletor would be $(".identify1")
Upvotes: 1