开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜