admin管理员组文章数量:1426652
I have the below jquery statement
$(this).('span.section1').css('background','url("images/accordion_closed_left.png") no-repeat scroll 0 0 transparent');
How do I write a if else statement for the css condition. What I mean is if the background image is accordion_closed_left.png then <do this>
or else <do this>
.
just to be precise <do this>
are blocks of statement.
Thanks for your time.
I have the below jquery statement
$(this).('span.section1').css('background','url("images/accordion_closed_left.png") no-repeat scroll 0 0 transparent');
How do I write a if else statement for the css condition. What I mean is if the background image is accordion_closed_left.png then <do this>
or else <do this>
.
just to be precise <do this>
are blocks of statement.
Thanks for your time.
Share Improve this question edited May 23, 2011 at 23:56 Felix Kling 818k181 gold badges1.1k silver badges1.2k bronze badges asked May 23, 2011 at 23:18 JayJay 3131 gold badge5 silver badges11 bronze badges 2- This is going to be slow and horrendous to maintian. Use classes instead. – jwueller Commented May 23, 2011 at 23:24
-
This is surely not correct:
$(this).('span.section1')
– Felix Kling Commented May 23, 2011 at 23:57
3 Answers
Reset to default 8I'd remend to use a css class instead and then call jQuery's .hasClass()
method on it:
css:
.closed {
background: url("images/accordion_closed_left.png") no-repeat scroll 0 0 transparent;
}
js:
var $target = $(this).find('span.section1');
if( $target.hasClass( 'closed' ) ) {
$target.removeClass( 'closed' );
}
else {
$target.addClass( 'closed' );
}
How to write this in jQuery
with 'guides' as a class name....
<script type="text/javascript" >
function guideMenu()
{
if (document.getElementById('guides').style.display == "none") {
document.getElementById('guides').style.display = "block";
}
else {
document.getElementById('guides').style.display = "none";
}
}
</script>
To naively answer your question:
if ($(this).('span.section1').css('background').match('|/accordion_closed_left\.png"|')) {
}
else {
}
However I support jAndy's answer, .hasClass() is the way to go!
本文标签: javascriptjquery if else condition for css apiStack Overflow
版权声明:本文标题:javascript - jquery if else condition for css api - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745438403a2658332.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论