I have the following click event
$(".element").click(function() {
var idNum = $(this).getID;
$('#new-'+idNum).fadeIn();
});
and the following function:
function getID() {
var elID = $(this).parent().attr('id');
return elID;
}
What I want is to be able to click on .element, get it’s parent’s ID, and then store that ID in the variable idNum. But this doesn’t seem to work. What am I doing wrong?
Instead of doing this code in another function, why don’t you just do it in the same one?
Since you can’t pass $(this) natively (it’s an object built into jQuery), you could instead search the DOM for the existence of a variable you pass (like the above code does).