Xeptor
Xeptor

Reputation: 477

Disable javascript in a element

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>

Upvotes: 8

Views: 151

Answers (4)

Ieuan Stanley
Ieuan Stanley

Reputation: 1258

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.

Upvotes: 0

Domain
Domain

Reputation: 11808

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

Upvotes: 2

Brian FitzGerald
Brian FitzGerald

Reputation: 3109

document.getElementById("a211094").removeAttribute("onmouseout");
document.getElementById("a211094").removeAttribute("onmouseover");

Upvotes: 1

CoderPi
CoderPi

Reputation: 13211

Overwriting the JavaScript:

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

Upvotes: 2

Related Questions