javascript - How to select an element that was created in a for loop? -
I have loaded lots of elements on my page dynamically in each list, one descriptor and one in each list A highlighter is overlaid on the image.
What do I want when a user enters the list item, the other element is highlighted.
My current code only highlights the last element in What is the best way to handle it? the last value assigned by it in Hover Time removed for event handlers, so you have to make sure that you have relevant values. Try putting the hover assignment inside the horse ... An optional method must be stored with the list item associated with the list item, such as ... Either work and they will give the same end result just choose what you like :) .viewer , no matter what list item I run.
(i = 0; i & lt; Ajax lang; ++ i) {var listid = 'listitem -' + i; Var mapad = 'mapitim -'; $ ('.list'). App ('& lt; div id = "' + listid + '" & gt; lots of text & lt; / div & gt;'); $ ('. Viewer') Attachment ('& lt; div id = "' + + + + '+'"> here it is ;); $ ('#' + Listid). Hover (function () {$ ('#' + mapid) .toggleClass ('Highlight');}); }
(I = 0; i & lt; Ajax; long; ++ i) { var listid = 'listitem -' + i; Var mapad = 'mapitim -'; $ ('.list'). App ('& lt; div id = "' + listid + '" & gt; lots of text & lt; / div & gt;'); $ ('. Viewer') Attachment ('& lt; div id = "' + + + + '+'"> here it is ;); (Function (Listed, Mapped) {$ ('#' + listid). Hover (function () {$ ('#' + Mapped). Togglic ('Highlight');})}}) (Listed, Mapad); }
for
(i = 0; i & Lt; Ajax.length; ++ i) {var listid = 'list -' + i; Var mapad = 'mapitim -'; $ ('.list'). App ('& lt; div id = "' + listid + '" & gt; lots of text & lt; / div & gt;'); $ ('. Viewer') Attachment ('& lt; div id = "' + + + + '+'"> here it is ;); $ ('#' + Listid) .data ("affiliate-map-id", mapbed); $ ('#' + Listid). Hover (function () {$ ('#' + $ (this) .data ("affiliate-map-id")). Toggleclass ('highlight');}); }
Comments
Post a Comment