开发者

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

开发者 https://www.devze.com 2023-02-18 02:42 出处:网络
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 C开发者_StackOverflowode\" href=\"#\" class=\"modalDlg\">

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 C开发者_StackOverflowode" 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 ?


Very simple way to do this.

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


Try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消