/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Attaching Events to Cell Table

Hello,
i have following problem. I generate dynamicly cells in table
and try to attach onmouseover and onmouseout events.
Code looks like this:
var suggest = $(‘t_suggest’);
for(i=0; i<items.length; i++){
var row = suggest.insertRow(-1);
var cell = row.insertCell(-1);
cell.innerHTML = items[i];
var f = function(){ cell.style.backgroundColor = ‘blue’; }
cell.addEventListener(‘mouseover’, f, false);
}

the code “works” but instead of particular cell always
the color of the last cell is being changed ?
Any ideas ?
I tried cell.onmouse…. the same effect, i event
tried to create tr’s and td’s and then appendChild
instead of insertRow and Cell, but still the same effect.
Im relative new to JavaScript so i can maybe “miss”
something.
Thanks for help,
Kuba

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangFeb 16.2010 — var f = function(){ [COLOR="Blue"]this[/COLOR].style.backgroundColor = 'blue'; }
Copy linkTweet thisAlerts:
@kubasauthorFeb 16.2010 — Thanks.. ?

Stupid me ?
×

Success!

Help @kubas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...