Jump to content

onMouseOver event


optikalefx

Recommended Posts

ok i found this

 

javascript: document.body.contentEditable = 'true'; document.designMode = 'on'; void 0

 

i want to make something similar to that, where it knows what tag your on, and can move it or change the text of it.  Any ideas on where to start?  Or at least just be able to envoke that command from an external js file and then be able to save the changed HTML code?

Link to comment
Share on other sites

an external js file can do things like:

var mylinks = document.getElementsByTagName('a'); //get all links in page and put in array
for (var onelink in mylinks) { // loop through all links
    // onelink contains a reference to the current link object
    onelink.onmouseover = functionname; //sets a fuction to be used when mousing over this link
    onelink.onmouseout = functionname2; // mouseout function
    onelink.style.color = 'red'; //changes all links to red
}
function functionname() { //mouse over function
    this.style = 'green';
}
function functionname2() { // mouseout function
    this.style = 'blue';
}

If you wanted to access an individual link, it would have to already have an id:

<a href="???" id="myid">link</a>

then you could get a reference to it like this:

var onelink = document.getElementById('myid');

and do things like the above with it.

if you want to get a reference to other types of items, just use the tag name in this statement:

var mydivs = document.getElementsByTagName('div'); //get all divs in page and put in array.

you could then do similiar things with that that I did with the links above

 

to get all the elements in the page, use the '*' selector:

var allelements = document.getElementsByTagName('*'); //get all elements in page and put in array.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.