Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / March 2004

Tip: Looking for answers? Try searching our database.

setAttribute and removeAttribute fail??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
haiwen - 04 Mar 2004 21:56 GMT
Hello, everyone

I have a html button
id=butPause onmouseover=onmouseover='this.style.backgroundImage="url(./Pause_glow.jpg)"
style=" BACKGROUND-IMAGE: url(./Pause_noglow.jpg"    onclick="playPause()" onmouseout='this.style.backgroundImage="url(./Pause_noglow.jpg)"'

it works well untill I wish to change its background, onmouseover and onmouse action after it is clicked

function playPause(

var butPause=window.document.getElementById("butPause")
butPause.style.backgroundImage="url(./Play.jpg)";// This works well

butPause.setAttribute('onmouseover','this.style.backgroundImage="url(./Play_glow.jpg)"')
butPause.setAttribute("onmouseout",'this.style.backgroundImage="url(./Play_noglow.jpg)"')

//  butPause.removeAttribute('onmouseover')
//  alert('butPause onmouseover='+butPause.getAttribute('onmouseover'))

The button's background does change after click, but the onmouseover and onmouseout do nothing

Could anyone help? I do appreciate your help.

Haiwen
bruce barker - 05 Mar 2004 01:18 GMT
don't set the attributes, set the methods instead.

function playPause()
{
    if (this.butPause = window.document.getElementById("butPause"))
    {
            butPause.style.backgroundImage="url(./Play.jpg)";// This works
well.
            butPause.onmouseover = new Function
('this.style.backgroundImage="url(./Play_glow.jpg)"');
            butPause.onmouseout = new
Function('this.style.backgroundImage="url(./Play_noglow.jpg)"');
    }
}

you might want to cache the images for faster rollovers:

var imgPlay = new Image(); imgPlay.src = "./Play.jpg";
var imgPlayGlow = new Image(); imgPlayGlow.src = "./Play_glow.jpg";
var imgPlayNoGlow = new Image(); imgPlayGlow.src = "./Play_noglow.jpg";

function playPause()
{
    if (this.butPause = window.document.getElementById("butPause"))
    {
            butPause.src = imgPlay.src;
            butPause.onmouseover = new Function ('this.src =
imgPlayGlow.src');
            butPause.onmouseout = new Function('this.src=imgPlayNoGlow
.src');
    }
}

-- bruce (sqlwork.com)

> Hello, everyone:
>
> I have a html button:
>  id=butPause onmouseover=onmouseover='this.style.backgroundImage="url(./Pause_glow.jpg)"'
> style=" BACKGROUND-IMAGE: url(./Pause_noglow.jpg" onclick="playPause()"
onmouseout='this.style.backgroundImage="url(./Pause_noglow.jpg)"'

> it works well untill I wish to change its background, onmouseover and onmouse action after it is clicked.
>
> function playPause()
> {
> var butPause=window.document.getElementById("butPause");
> butPause.style.backgroundImage="url(./Play.jpg)";// This works well.

butPause.setAttribute('onmouseover','this.style.backgroundImage="url(./Play_
glow.jpg)"');

butPause.setAttribute("onmouseout",'this.style.backgroundImage="url(./Play_n
oglow.jpg)"');

> //  butPause.removeAttribute('onmouseover');
> //  alert('butPause onmouseover='+butPause.getAttribute('onmouseover'));
[quoted text clipped - 6 lines]
>
> Haiwen

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.