Multi-click event handling in jQuery where order is important

I am working on php that uses ajax application. On all links where I want to get the link captured by jQuery, I add the ajaxlink class directly to the link

<a class="someclass ajaxlink" href="somelocation1">goto1</a>
<a class="someclass ajaxlink" href="somelocation2">goto2</a>
<a class="someclass ajaxlink" href="somelocation3">goto1</a>

Javascript looks something like this:

$('.ajax-link').click(function(){get link with ajax});

If the user has JavaScript enabled, he will receive the page through ajax. One specific one, I have one multi-page page, so I have the same function to create the same link for all pages.

Now my problem is only in one of the links on one page, I want to do something else. It should run another function when the ajax page returns successfully. Now I have such code.

<div class"specialclass">
    <a class="someclass ajaxlink" href="somelocation1">goto1</a>
    <a class="someclass ajaxlink" href="somelocation2">goto2</a>
    <a class="someclass ajaxlink" href="somelocation3">goto1</a>

    <a class="someclass ajaxlink special-1" href="somelocation">goto</a>
    <a class="someclass ajaxlink special-2" href="somelocation">goto</a>
    <a class="someclass ajaxlink special-3" href="somelocation">goto</a>
</div>

$('.ajax-link').click(function(){get link with ajax});
$('.specialclass .special-1,
   .specialclass .special-2,
   .specialclass .special-3').click(function(){get link with ajax});

, , , , . , . , , . .

, , ajaxlink. , , ajaxlink .

- .

+3
2

:

var normalClick=function(){/*get link with ajax*/};

$('.ajax-link').click(normalClick);
$('.specialClass').click(
  function(){
    normalClick();
    /* special click code */
  }
);
+3
+1

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


All Articles