javascript - Dynamically Written script not functioning -
I'm bashing my head against a wall for about 4 hours, trying to figure out That's why it does not work I have a program that needs to write code based on the number of results from SQL query.
I am using an easy library. When it's hard-coded, it works:
& lt; Body id = "body" onload = "bodyLoaded ()" & gt; & Lt; An id = "link" href = "# test" title = "snowflake" rel = "lightbox" & gt; Hello & lt; / A & gt; & Lt; Div id = "test" style = "display: none; width: 320px; height: 240px" & gt; & Lt; P & gt; Test Content & lt; / P & gt; & Lt; / Div & gt; & Lt; Script type = "text / javascript" & gt; Function body loaded ($ {'(# link'). Etr ('onclic', 'logext ("hello")'); } Function log text (message) {console.log (message); } & Lt; / Script & gt;
However, when the link has been written dynamically in this way, then the EasyBox popup is not a fire.
& lt; Body id = "body" onload = "bodyLoaded ()" & gt; & Lt; Div id = "test" style = "display: none; width: 320px; height: 240px" & gt; & Lt; P & gt; Test Content & lt; / P & gt; & Lt; / Div & gt; & Lt; Script type = "text / javascript" & gt; Function Bowdered () {document.getElementById ('body'). Internal HTML + = "& lt; an id = 'link' href = '# test' rel = 'lightbox'> Hello
Any idea why this will work? I'm pulling my hair here!
I do not understand why you are not just using jQuery for all of this . Hello
If .click () does not work, then you can also try. Both worked for me in JSfield (http://jsfiddle.net/LZxrL/ and).
Besides, why does no one say that there is no element with id = 'body', when the body element has the 'body' id. Obviously, he wants to add a link to the body.
Edit: I just read about a comment about the lightbox on the second post, not on the click event. That thing changes. I am not quite familiar with the plugin with the authorization, but I suspect that the plug-in looks for rel = "lightbox" when the page loads and gets an element later will not go. Most plugins have a manual method, such as something:
$ ('# link'). Lightbox ();
Comments
Post a Comment