javascript - Set new object location on button click? -


i'm trying figure out change object's location on screen when clicks button. example image 1 should move {'x' : '300' , 'y' : '200'}, when button clicked.

any suggestions? thanks!

given have following in html layout:

<button id="button1">click</button> <img src="..." id="image1" /> 

you can in script file (pure javascript):

var button1 = document.getelementbyid("button1"); var image1 = document.getelementbyid("image1");  button1.click = function() {     image1.style.position = "absolute";     image1.style.top = "300px";     image1.style.left = "200px"; }; 

or jquery/zepto.js:

$(function() {     $("#button1").on("click", function()     {         $("#image1").css({position: "absolute", top: "300px", left: "200px"});     }); }); 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo