Search code examples
javascriptjquerygethref

Problems to get address using onmouse over


What is the best way get address value from <a> tag using onmouseover event?

<a href="http://facebook.com" onmouseover="">something</a>

Solution

  • <a href="http://facebook.com" onmouseover="alert(this.getAttribute('href'))">something</a>
    

    Working demo.

    You can store this result in variable using following code:

    document.getElementsByTagName('a')[0].onmouseover = function() {
        var hrefValue = this.getAttribute('href');
        alert(hrefValue); // use hrefValue
    }
    

    Working demo.