javascript - Jquery replacing image issue -


i'm using following script change image based on value entered.

var sitelogo = $('input#site-logo').val(); $('#site-logo, img').attr("src", sitelogo); 

html

 <div id=site-logo> <img src="default.png" width="285px" height="100px"> </div>  <input id="site-logo" class="input-xlarge" placeholder="http://" type="text"> <button id="add-site-logo" class="btn" href=""> add</button> 

my issue it's changing all images on page value in site-logo. how make only value in site-logo gets changed , not other random stuff on page?

remove ',' jquery selector

$('#site-logo img').attr("src", sitelogo); 

$('#site-logo img') means images inside #site-logo

$('#site-logo, img') means #site-logo plus images.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -