user3332274
user3332274

Reputation: 209

Disable Links in this jquery code

I'm a total noob in Javascript and trying o disable a link in the following code.

It's the .title_link_out. Whenever i click the div that has this class, the homepage loads (href="#"). I want to disable the link without renaming the class or having the function destroyed.

I hope somebody can help without further information. This is just the code snippet that is responsible for the link.

Any idea when seeing this code?

jQuery(document).ready(function(e) {
  e(".squareDemo_production").unbind("hover");
  e(".squareDemo_production").hover(function() {
    e(this).find('.squareLitDemo.shape').css('cursor', 'pointer');
    e(this).find('.squareLitDemo.shape').on('click', function() {
        console.log('ff', e(this).find('.title_link_out').attr('target'))
        if (e(this).find('.title_link_out').attr('target') == 'blank') {
        var win = window.open(e(this).find('.title_link_out').attr('href'), '_blank');
        win.focus();
        }
        else{
        window.location.href = e(this).find('.title_link_out').attr('href');
    }
    })

I tried the following in CSS, but it didn't work.

.title_link_out {
pointer-events: none!important;
cursor: default!important;
}

Upvotes: 0

Views: 65

Answers (1)

Huey
Huey

Reputation: 5220

To dynamically disable a href links, usually e.preventDefault() is used:

$('.title_link_out').click(function(e) {
    e.preventDefault();
});

More information is available at the jQuery Tutorial

Upvotes: 1

Related Questions