intboolstring intboolstring - 1 year ago 55
HTML Question

Coexistence of ID And CLASS on an HTML tag

So I'm writing some HTML that uses jQuery and CSS. I want to use a system where I have

to manage the CSS and have an
to have jQuery reference. I can't just call the jQuery by class name because I have several div boxes of the same class.

All together, is it OK to do something like the following?

<p id="id" class="css">Text</p>

Also, if it is ok, is it proper to do it that way?
Is there a better way I could do this?

Answer Source

Combining class and id is OK as long as the id is unique.

Use # for id and . for class.


<p id="id" class="css">Text</p>

If you don't want to name each div with a unique ID you can also get the div using class just get the index

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download