0

I am having an issue with the a href="#" still working when the link is clicked - I can see the console.log() before the page changes - why is it doing this?

HTML:

<a href="#" id="brands_by_category_change_name_btn" class="btn btn-primary" >Save</a>

JS:

        $('body').on("click", "#brands_by_category_change_name_btn", function () {

            var self = $(this);
            var id = $("#product_name_head").data("productid");
            var cat_id = $(".product_category_selector").data("id");

            var url = $("#manufacturers_table").data("infourl");

            var state = "0";
            if(self.is(":checked"))
            {
                state = "1";
            }
            var data_array = { 
                    id : id, 
                    cat_id : cat_id, 
                    state : state
                };

                console.log(url);

            //ajaxCall(url, data_array, null, "reload_selected_product_categories");

        });  
1

3 Answers 3

7

You should pass event parameter to function. And do. Event.preventDefault() it will stop link from native behavior.

Sign up to request clarification or add additional context in comments.

Comments

0

Adding return false; at the end of the function will fix the problem

Comments

0

Add a return false; at the end of your event-handling code. I would do it that way:

$("#brands_by_category_change_name_btn").click( 

  // your code...

  return false;

}); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.