Problem with disabling JREERY href

I'm currently working on a homemade 100 percent javascript CMS in our office and I have a problem. Some editable areas that the user can edit are contained in the href link. These hrefs are NOT editable, but when the user clicks on these zones (in edit mode), the browser follows these links.

First, heres an example of html generated by CMS:

<span id ="8a8b8d2e262bde2d01262c08317c000c" class="document">

    <a href="/actions/ecommerce/viderSelectionPalierEtVitrine">
            <img src="/images/logo.gif" id="8a8b8d2e262bde2d01262c08bf83000d" title="" alt="" class="image logo" />
    </a>        
</span>

Here, for example, the user can only change; So I tried to control the surrounding href this way:

        var referenceZone = $(this).attr("id");
    $("#"+documentId+" a").each(function() {
        $(this).click(function() {
            return false; 
        });
    });

Where referenceZone is my environment <span id ="8a8b8d2e262bde2d01262c08317c000c" class="document">

Is it really that hard as it seems to me?

<**** EDIT ****> Added sandbox for testing purposes here: http://jsbin.com/aboke/2

<**** EDIT 2 ****> I do not understand that alert (event.type) doesn't even work !!

//click event disabling on any href of curently edited ${"span.document"}
    $("span#" + documentId + " a").click(function(event) {
              alert(event.type);
              event.preventDefault();
      suppressionZoneModifiable(documentId);
          recupererTexte(referenceZone, documentId);
    });         
+3
3

http://jsbin.com/aboke/2 . :

1. ,

:

renduZonesModifiables(8a8b8d2e262bde2d01262c08317c000c);

2. span

8a8b8d2e262bde2d01262c08317c000c 8a8b8d2e262bde2d01262c08bf83000d

3. onclick jQuery

$(this).onclick = function() { return false; }

$(this).click(function(e) {
     e.preventDefault();
});

4. js

") " ( 81)

+2

, , return. preventDefault();

var referenceZone = $(this).attr("id");
$("#"+documentId+" a").click(function(event) {
    event.preventDefault();
});

, .each(), . event.preventDefault().

. .

+3
$(this).click(function() {
    return false; 
});

^ does not work. Using $(...).click()adds this function to the list of functions that it performs when clicked. It does not remove the default behavior after the link.

You can override the default link action by doing:

this.onclick = function() { return false; }
-1
source

Source: https://habr.com/ru/post/1729227/


All Articles