I’m trying to pass an element’s id to storePair
$("#someid").click(storePair($(this).val(),$(this).attr("id"));
using $(this) doesn’t work. no value.
Another stackoverflow post suggests that I use an anonymous function as a wrapper for StorePair(val,id), i.e.,
$("#someid").click(function(){storePair($(this).val(),$(this).attr("id")});
That seems kind of roundabout… Is there a way to call StorePair and pass the value and id without using the anon function?
You can use
thisinside thestorePairfunction to get what you’re after, like this:Then bind it like this:
Or, use an anonymous function like you already have, round-about or not, it’s the way it works 🙂