| | |
change input's bg image with js
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
this is the input...
<input blah blah blah class='someclasss' onclick='changeSrc(this)'>
.someclass
{
background-image:url(someimage.someformat);
}
function changeSrc(clicked)
{
clicked.style.backgroundImage = 'someotherimage.someformat' //this won't work in IE7!
}
Manipulate the code freely. thanks
<input blah blah blah class='someclasss' onclick='changeSrc(this)'>
.someclass
{
background-image:url(someimage.someformat);
}
function changeSrc(clicked)
{
clicked.style.backgroundImage = 'someotherimage.someformat' //this won't work in IE7!
}
Manipulate the code freely. thanks
You need an id on the same object with someclass. That id becomes the target of the assignment statement:
Put both the class and the id in the object with the background
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function changeSrc(clicked) { changeme.backgroundImage = 'someotherimage.someformat') }
Put both the class and the id in the object with the background
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<body class="someclass" id="changeme">
Daylight-saving time uses more gasoline
•
•
•
•
function changeSrc(clicked)
{
clicked.style.backgroundImage = 'someotherimage.someformat' //this won't work in IE7!
}
javascript Syntax (Toggle Plain Text)
function changeSrc(clicked) { clicked.style.backgroundImage = "url(imageName)"; //the above stmt assumes that the image is present //in the same path as that of the html file }
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
- change image one by one (ASP)
- I Need Help Making A Rollover Image! (Geeks' Lounge)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Help needed working with prototype.js and php
- Next Thread: javascript issue
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate array automatically beta box browser bug calendar captchaformproblem cart checkbox child class codes column createrange() css cursor decimal dependent design disablefirebug dom download dropdown editor element engine enter error events explorer ext file firefox focus forms frameworks google gwt html htmlform ie8 iframe images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jsp jump listbox masterpage math menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent pdf php player post problem progressbar prototype redirect regex runtime scale scroll search select session shopping size sql text textarea toggle w3c web website window windowofwords windowsxp wysiwyg \n






