I want to append a script generated in javascript inside a div created before in HTML, the problem is that only works if
$("<script />", {
"src":"http://en.parkopedia.co.uk/js/embeds/mapView.js",
"data-location":"http://en.parkopedia.co.uk/parking/" + search_field2,
"data-options":"l=0&tc=0&zc=1&country=UK&ts[]=4&ts[]=3&ts[]=2",
"data-size":"650:400",
"id":"script_map",
"type":"text/javascript"
}).appendTo("body")
but if I change that for "$('#divId')" does not work, so the questions are:
- How can I append that script generated inside a div when you click into a button?
- How can I prevent to duplicate the script when I click twice in the button? Because it's working inside the body, but when I click again it shows two script windows. So i should remove the script before create a new one or if I get to put inside the div, clean all the childs inside.
I've created a demo here:
Update: The main aim is to update the data-location when you click on the button and send the text inside the box to the data location to search there and show the script map below the textbox. Maybe it is another simple way to do it.
<head>, not in the<body>. and if you only want it to happen once, then set a flag variable and check for it next time. e.g.if (!script_set) { ...insert script ... ; script_set = true; }<div id="map", it works fine ! jsfiddle.net/kishoresahas/oosttuc0/12.requirement (aviod duplicates) jsfiddle.net/kishoresahas/oosttuc0/3