Null Pointer
Null Pointer

Reputation: 9309

Changing class of a div using parent's id - jquery

In my page there is an <a> tag and inside that there is a <div>. that is shown below:

 <a id="test"  title="Change Color Code" href="#" class="modalDlg">
     <div class="<%:(colorCode) %>">

     </div>
 </a>

How can i change the class of <div> when i click on another button in that page ( i only have the id of the hyperlink (ie , test ) ).

Can i change the class of that <div> using the hyperlink id (which contains that div) using jquery ?

Upvotes: 1

Views: 306

Answers (2)

daryl
daryl

Reputation: 15207

Very simple way to do this.

$(function() {
    $('#button').click(function() {
        $('#test div').addClass('foo');
    });
});

Upvotes: 2

Chandu
Chandu

Reputation: 82933

Try this:

$("<YOUR_BUTTON_SELECTOR>").click(function(){
    $("#test div").addClass("<YOUR_CLASS_NAME>");
    // OR $("#test div").removeClass("<YOUR_CLASS_NAME>");
});

Upvotes: 2

Related Questions