So I have captured the ID of an image in a jquery variable like so:
$("#tag img").click(function(e) {
var element = $(this).attr("id");
How do I then parse the var element?
I would like to put it in an if statement like this:
if ( $(element *= 'square' ) {
$('#tag #view_name').text("Tag with a Square");
}
elseif ($(element *= 'circle' ) {
$('#tag #view_name').text("Tag with a Circle");
}
How do I do that, with the least amount of code possible?
Thanks.
Edit: Oh, and the text I am searching for are the two strings in the single quotes ('square' and 'circle').
Edit: All of the answers below look like they should be working...but they aren't. Here is the other code, so you guys can see if I am missing something:
<div id="tag">
<a href=""><img src="images/square.png" id="square-tag"></a> |
<a href=""><img src="images/circle.png" id="circle-tag"></a> |
<span id="view_name">Tag with Square</span>
</div>
Edit 3: Ok...it seems that some other jQuery was hijacking that div. All the answers are right. I wish I could mark all of them correct :)