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!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745438404a4627716.html
评论列表(0条)