Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  166] [ 4]  / answers: 1 / hits: 21162  / 13 Years ago, fri, april 22, 2011, 12:00:00

Ok, so this is probably obvious.



I need to get the ID of a clicked div:



$(div.editable).click(function(e) {  
var editid = $(this).attr(id);
});


And the use that ID in a function w/parameters:



ajaxStyle(value, 2, editid)


But it doesn't work when I write it like this. It either returns undefined or just doesn't work.


More From » jquery

 Answers
46
var editid;
$(div.editable).click(function(e) {
editid = $(this).attr(id);
});


It's all about function scope.


[#92601] Thursday, April 21, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breonnamayah

Total Points: 574
Total Questions: 115
Total Answers: 96

Location: England
Member since Sun, May 21, 2023
1 Year ago
breonnamayah questions
;