I am using jQuery. I call a JavaScript function with next html:
<li><span><a href='javascript:uncheckEl('tagVO-$id')'>$tagname</a></span></li>
I would like to remove the li element and I thought this would be easy with the $(this) object. This is my JavaScript function:
function uncheckEl(id) { $('#'+id+'').attr('checked',''); $('#'+id+'').parent('li').css('color','black'); $(this).parent('li').remove(); // This is not working retrieveItems(); }
But $(this) is undefined. Any ideas?
Try something like this (e.g. to hide the
<li>):And your link:
$(this)is not present inside your function, because how is it supposed to know where the action is called from? You pass no reference in it, so$(this)could refer to everything but the<a>.