How can one use an image as a button to change the color of a div element in JavaScript?
-
Please suggest the exact code to do so!
-
Answer:
Wrap image with an "a" tag and use javascipt function on "onclick" event.
Milen Iliev at Quora Visit the source
Other answers
u can just do it bye using div-id:hover <div id="try"> <input type="button" value="button" style=background-color:green;/> </div> in css u can write : #try:hover { background-color-red; } same u can apply for an image too, instead of writing background-color u can give the image source. in javascript u can use the function "onclick" event .
Priyam Srivastava
HTML<img src="abc.jpg" onclick = "changecolor()" id="image1"></img> <div id="div1"></div> JavaScript:function changecolor(){ document.getElementById("div1").style.color = "red"; }; jQuery:$('#image1').click(function(){ $('#div1').css('background','red'); //Changes div background to red });
Rohit Falor
Related Q & A:
- How to add an image to a button?Best solution by Stack Overflow
- How can I use a button to retrieve a phone 'number' from contacts?Best solution by Stack Overflow
- How can we use our PC as a voice recorder?Best solution by Yahoo! Answers
- How can I use my PC with a wireless printer?Best solution by pcmag.com
- How can i use my laptop as a monitor for my xbox 360?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.