admin管理员组文章数量:1425732
I'm trying to execute jQuery code when a div's style changes from display: none;
to display: block;
I'm using tabs that's why this div's style changes like this, and this jQuery code should only be running when viewing this tab only.
so how can I achieve this ?
and thanks.
EDIT: I tried .is(':visible');
and it only works if we load the page and this div is visible, not if this div will be visible later.
I'm trying to execute jQuery code when a div's style changes from display: none;
to display: block;
I'm using tabs that's why this div's style changes like this, and this jQuery code should only be running when viewing this tab only.
so how can I achieve this ?
and thanks.
EDIT: I tried .is(':visible');
and it only works if we load the page and this div is visible, not if this div will be visible later.
- 2 Why not execute the code when a user clicks on the other tab? – Celos Commented Apr 30, 2012 at 10:43
- yes maybe this will work, but I want to know if it's possible to do this using jQuery, listening when something happened ? – Pierre Commented Apr 30, 2012 at 10:54
- @Alnitak ok so I guess I have to do it the way Celos suggested above. – Pierre Commented Apr 30, 2012 at 11:00
- @Peter yeah, it's normally quite easy to trap any event which changes the displayed tab. – Alnitak Commented Apr 30, 2012 at 11:03
4 Answers
Reset to default 2What you're looking for are DOM Mutation Events, which can raise an event when a DOM element is inserted, deleted or modified.
Unfortunately they were never well supported, and were deprecated in DOM3.
In any event (no pun intended), in your case it would be simpler just to catch whatever UI event it is that causes the tab to be displayed.
if($("#myTab").is(':visible')){
here is your code ...
}
try something like this:
if($(DIV).is(':visible')) { // DIV => valid selector of your target
// execute your code
}
OR:
if($('body').on('EVENTNAME', 'DIV:visible')) { // DIV => valid selector of your target
// execute your code
}
$(document).ready(function(){
$(your tab container).click(function(){
//set none property to all of your id's
var obj=$this;
if(obj){
$("your id").style.display="block"; // set block to your current item
}
});
});
or
if($("you id").is('visible')){
//do it
}
本文标签: javascriptHow to execute jQuery code if a div display style changes from none to blockStack Overflow
版权声明:本文标题:javascript - How to execute jQuery code if a div display style changes from none to block? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745372760a2655804.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论