javascript - Add dynamic variable to onclick event -


i have onclick event loads iframe. need able dynamically change part of url in onclick event. what's best possible way this? part need dynamically replace highlighted below ****variable here***.

var ****variable here*** = '343h343432e';  <button type="button" id="load_2" class="btn btn-info" onclick="document.getelementbyid('attri_map').height = '520';document.getelementbyid('attri_map').src='https://example.com/****variable here***';document.getelementbyid('load_2').style.display = 'none';">click load</button>  <iframe id='attri_map' width='100%'  height="0" frameborder='0' allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe> 

this opportunity extract out javascript, inline isn't practice.

remove onclick event on element in html, can do:

(i've put attri_map variable remove overhead of re-querying dom same element.)

var variable = "example";  document.getelementbyid("load_2").onclick = function () {     var attrmap = document.getelementbyid('attri_map');     attrmap.height = '520';     attrmap.src='https://example.com/' + variable;     document.getelementbyid('load_2').style.display = 'none'; }; 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -