Jquery - determining which link was clicked

后端 未结 5 2004
轮回少年
轮回少年 2020-12-20 07:18

I have several similar links that trigger different navigation divs to appear. I am trying to find a way in JQuery to determine which of the links was clicked and then trig

5条回答
  •  一个人的身影
    2020-12-20 07:46

    This is my html page (Django template):

    {% for blog in blogs %}

    {{ blog.title }}

    Created: {{blog.date_created|date:'d M Y'}}

    {{ blog.brief|safe }}


    {% endfor %}

    In my javascript file, this is what have and it works.

    $(document).ready(function() {
    
        console.log("document is ready!!!")
    
        $('#id_bloglist').on("click", 'a#publish,a#remove', function(e) {
    
        e.preventDefault()
    
        var pk = $(this).attr("href")
    
        if ($(this)[0].id == 'remove'){
            console.log("remove link clicked, calling deleteBlog with pk = " + pk)
        }
        else if ($(this)[0].id == 'publish'){
            console.log("publish link clicked, calling publishBlog with pk = " + pk)
        }
    
        return false;
       });
    });
    

提交回复
热议问题