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
Post a Comment