Forum Moderators: open

Message Too Old, No Replies

Looping to find a match on a dynamically generated pag

         

ocon

11:04 pm on Aug 10, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



I am using a JavaScript API that creates a complex map and attaches it to a <div> tag hardcoded on my page. This script runs on window.onload. My problem is that I need to modify one of the JavaScript created elements (another <div> tag) once it's created. I've tried to add this script right after the map is initialized, but I guess that element hasn't been downloaded/constructed yet because it doesn't get modified. I know my script is good because I made a hardcoded element on my page to run this script onclick.

Is there a way to create a script that checks to see if this element exists. If it doesn't, check again every X-milliseconds. If it does, run the modification script and don't look for this element again.

Would that even be the right approach?

With the help in another post, my modification script uses jQuery and looks like this:

function modification(){
$("div.gmnoprint").each(function(){
var index_current = parseInt($(this).css("zIndex"), 10);
if(index_current == 10) {$(this).css("margin-top", "91px");}
});
}

lostdreamer

9:20 am on Aug 11, 2011 (gmt 0)

10+ Year Member



I would not try and check for the element every XX ms unless not possible any other way.

"My problem is that I need to modify one of the JavaScript created elements...."

Can you perhaps show the code that creates this element? You probably have to set up the 'modification code' right behind it.