8

I have an element with a a script for a mouseover to show an image. I can't change the HTML, so is it possible to disable the javascript in the link, but still keep the link for the href intact? I cant use the id of the a element since it isn't unique.

HTML:

 <div class="container">
<a id="a211094" onmouseout="etim();" onmouseover="stim('/imgs/7c24b548-4f4c-418e-ad4f-53c73cf52ace/250/250',event,this.id);" href="/products/Computers/Desktops/Acer/Acer-Aspire-TC-705W-Towermodel-1-x-Core-i3-41?prodid=211094"><img src="" alt="">
</a>
</div>
3
  • 1
    What can you modify? Can you put extra JavaScript into the page? Commented Nov 24, 2015 at 13:48
  • 1
    Yeah I can add javascript and jQuery Commented Nov 24, 2015 at 13:52
  • 1
    your code went missing? Commented Nov 24, 2015 at 14:08

4 Answers 4

2

if you want to make all ancher tag or you can give class for those anchor tags on which you want to perform this and instead of $( "a" ) write $( ".myClass" )

$( "a" ).each(function( index ) {
$( this ).removeAttr("onmouseout");
$( this ).removeAttr("onmouseover");
});

use can use attr("disabled", "disable"); to disable it

Sign up to request clarification or add additional context in comments.

Comments

2

Overwriting the JavaScript:

document.getElementById("a211094").onmouseover = null
document.getElementById("a211094").onmouseout = null

6 Comments

I cant use the id of the link - I have a bunch of them with different Id. i tried document.getElementsByClassName and nested the a class with the parent cotnainer but that didnt work.
HTML DOM getElementsByTagName() Method: w3schools.com/jsref/met_element_getelementsbytagname.asp
Thanks for the reply. Not sure how to use this?
smilar way you use document.getElementsByClassName
The link contains an Example with a loop, it will help you
|
1
document.getElementById("a211094").removeAttribute("onmouseout");
document.getElementById("a211094").removeAttribute("onmouseover");

2 Comments

now you provided 2 wrong answers in a short time WITHOUT any comment or explanation -.- this it not how you should do it.. -1
Actually, the answer was correct. As I said, it was a typo. Now run along.
0

If you can consistently access and control the containing element you could try a slightly left-field approach using an onmouseover event on the container.

There's a function called setCapture() which you can call during a mouse event to "capture" all mouse events of that kind for the element it's called against, until a mouseup event or releaseCapture() is called. So you could do something like the following:

jQuery(document).ready(function() {
    $container = jQuery("#<yourcontainerid>");
    $container.on("mouseover", function(e) {
     if (e.target.setCapture) e.target.setCapture(true);
    });

    $container.on("mouseout", function() {
        document.releaseCapture();
    });

});

The (true) argument is important (I think, without testing) as it prevents any descendent events firing, which is what you want here.

The mouseout function will then release the capture when it leaves the area of the container.

Will this work? can't say for sure, I haven't tested it in your exact case, but in theory it should!

UPDATE: you can use ".container" rather than "#yourcontainerid" in the JQuery if you so wish to enable this for everything of class container.

1 Comment

Hey thanks for the effort - it didn't work though. Didn't throw an error but the event still fired.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.