Shade Posted March 8, 2009 Share Posted March 8, 2009 var a = document.getElementById('mydiv').style.BackgroundPosition; returns "10px 20px", probably a string. so, how to get x and y values for two variables ?like var x = x-position(10) var y = y-position(20)as integers to manipulate with ??a little function to extract and assign the two integer values to my choice of variables ?? Link to comment Share on other sites More sharing options...
jeffman Posted March 8, 2009 Share Posted March 8, 2009 var s = document.getElementById('mydiv').style.backgroundPosition;x = s.substr(0, s.indexOf("px"));y = parseInt(s.substr(s.indexOf(" "))); That does what you want. You haven't explained what you want it for, but I have a strong suspicion there is a better way to do it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.