Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add event listener to div background image change

Status
Not open for further replies.

coderubycode

Programmer
Nov 26, 2012
2
Is it possible to add an event listener that checks when the background image of a div has been changed?

document.getElementById("thediv").addEventListener('detectifmybackgroundimagehasbeenchanged', function () {
 
assuming you mean when the bg-image is changed by javascript, on load, store the value of the background image in a variable. use a setInterval function to retest this every x seconds. if the value has changed store the new value, execute your code.

I don't know any other way.
 
I'm not sure this is the best solution. I'm actually doing an app in phonegap but the problem I'm dealing with deals entirely with javascript so I will provide more details here in hope you can help me sort it out.

I have a window.onload function that basically generates an HTML5 Canvas, and it can only receive instructions from within the function. So in order to pass it a value, I need to bind an event listener to a link in the HTML which is outside the function. You can see this below, how it works for an instruction that comes from a button click


Code:
window.onload = function() {
.
.

 document.getElementById("toTop").addEventListener("click", function() {
          yellowBox.moveToTop();
          layer.draw();
        }, false);
.
.

}

This works fine. The problem I'm having is that I need to send it a value from the camera. Now this is all done with Javascipt as well through the following function:

Code:
function onPhotoURISuccess(imageURI) {

	alert(imageURI); //or do whatever you want with this value.. I need to pass this back to the window.onload function
	
}

The problem is that this phonegap function lives outside the window.onload function and how can I pass this imageURI back to the window.onload function?

I thought of creating an invisible div somewhere on the page, passing it the value of imageURI and then having an event listener bound to this div listen to when this is happening and pass that value back in the window.onload function.

Surely there must be a better way to do this, I think I'm missing some fundamental Javascript knowledge here.
 
store a value in the global scope and then have setInterval test the value. just like in my first post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top