Display content when ID has class using jQuery Display content when ID has class using jQuery xml xml

Display content when ID has class using jQuery


The easiest way I think would be to give the 'buttons' a shared class and a custom id. Then use jQuery to read the custom id of the clicked buttonclass-item and use a naming policy on the class of the description to make that display correctly.

Html:

<a href="#" class="myResources" id="resource_1">    <h2>resource 1</h2></a>

And Javascript/jQuery:

$(".myResources").click(function() {//And use the same id as class of the description for easy targetting.var resName = $(this).attr('id');    $('.'+resName).show();});

Hope this is something like what you we're looking for. Might not be the cleanest solution.HTML5 custom data-attributes might be a better fit.


If you want to check whether your element has a class or not, you can use jQuery's hasClass() function:

$('a').click(function () {if( $(this).hasClass('yourClass') ) {   //Do whatever this class needs to doelse { // Do other stuff...

More information on the hasClass function can be found in the JQuery API Documentation


Had your tried to alert("class added "+$(briefInfo).attr("class"));

if you got the right alert then you can use your logic in this way by using the class.