AnsweredAssumed Answered

Apply an onclick function to dynamically created anchor tags

Question asked by mdk on Oct 12, 2017
Latest reply on Oct 16, 2017 by mdk

I have successfully called a function ("kr_highlight") that creates map graphics of xy locations onto the map when the anchor tag is clicked WHEN my widget has the anchor tags hard coded into the widget.html page.

 

But now I want, after the widget loads, the anchor tags generated dynamically through js when the user clicks an "expand" link inside the widget.html page which populates the div.innerhtml.  During the dynamic generation I want to apply either an onclick function or an eventlistener to the id's of the dymaically generated anchor tags.  When I change I try to do this dynamically I get:

 

"Uncaught ReferenceError: kr_highlight is not defined"

 

where "kr_highlight" is the function being called from the onclick event. 

 

:

for (x in b){

   //dynamically create anchor tags

}
  

 

 

Version 1:

 

//now apply the onclick event to each id version 1

var id = document.getElementById("31");

        id.addEventListener("click",function(){
            kr_highlight('38.358569,-81.71833');
         });

Another version:

//now apply the onclick event to each id version 2

on("31", "click", kr_highlight('38.358569,-81.71833;;'));

Outcomes