www.webdeveloper.com
Results 1 to 3 of 3

Thread: Using onmousedown and onmouseup for the .getElementsByClassName method

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Posts
    4

    Using onmousedown and onmouseup for the .getElementsByClassName method

    Hi people,
    I have a class of links defined as .button, they are highly stylized and look like links. I want to set it so that
    onmousedown, the background color and border style will change, and will change back to what they were onmouseup. Currently I have functions defined as mDown(x) and mUp(x), where I use x as the parameter and then change them to mDown(this) and mUp(this) as onmousedown and onmouseup attributes of every button. I was wondering if there is a way to set the onmousedown and onmouseup actions for the class as a whole. By the way, in the below code the
    element with ID "box" is the table cell in which all of the buttons are located. I was thinking something like this:
    var y=document.getElementById("box").getElementsByClassName("button");
    y.onmousedown="mDown(y)";
    y.onmouseup="mUp(y)";

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    No, you'll have to set the onmousedown and onmouseup on all elements individually, which is easily achieved with a loop. getElementsByClassName returns an array.

  3. #3
    Join Date
    Jan 2013
    Posts
    4
    I am adding something where users can open up a small selection pane on the side and select their teachers, and buttons will be created on the main page that link directly to their teachers' homepages. Is there a way that I can add onmousedown and onmouseup functions to these new button through JavaScript/DOM?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles