| | |
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 ajaxexample ajaxjspservlets array browser captchaformproblem cart checkbox child class close codes css date debugger decimal dependent design disablefirebug dom editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onerror onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming prototype rated redirect runtime safari scale scriptlets scroll search security session shopping size software star stars toggle unicode variables web webservice wysiwyg \n






