I am making an accordian menu.
I just found this link http://jsfiddle.net/zM5Vj/ , and it is almost similar to the accordian menu I have made.
In the code, where there is
if($(this).text() == "-")
{
$(this).text("+");
}
else {
$('#accordion .opener').text("+");
$(this).text("-");
}
});
If insted of "+" and "-", i want to put icons "~/Image/iconplus.gif" and "~/Image/iconminus.gif". How do i do so?
I have tried
<img src="..."/>
But still it is of no use.
Please can anyone help?
Thanks in advance.
Thank You All for responding and helping me in solving it.
@Simon Adcock, Your answer gave me a new way to think about the solution.
However, i also found a 1 line solution to it.
I just added this line to my .js file
So, answer finally it is :
$(this).text()
allows you to specify plain text content for an element. To attach an image, use$(this).append($(<img src='plus.gif'))
.Also, instead of using
$(this).text() == '-'
to see if the menu has been expanded, attach a class to the<a>
element.For example, we can use
.addClass('expand')
to indicate that the menu has expanded, and then.hasClass('expand')
to check whether the menu has expanded, and finally'.removeClass('expand')
to indicate that the menu is no longer expanded).Here's an example, using dummy images to illustrate:
JSFiddle