Diego M.
Diego M.

Reputation: 55

How to replace url instead add/push in this code

Sorry guys, noob jQuery question. I found this code to change the url depending on which checkbox is selected here: Change href depending on checkboxes But I need to replace the url instead add the checkbox value to the url.

Like I'm on www.katana.com/e-bikes/ and I want to redirect to www.katana.com/product/whatever not want to stay on e-bikes subpage and continue adding the value to the url.

Thank you so much!!!

$(document).ready(function() {
    $('.checkbox').on("change", function() {
        var aHrefVals = [];

        $('.checkbox').filter(":checked").each(function() {
            aHrefVals.push($(this).val());
        });

        $("a").attr("href", aHrefVals.join(","));
    });
});

Upvotes: 3

Views: 479

Answers (1)

reachtokish
reachtokish

Reputation: 356

If you do window.location.origin you will get www.katana.com . Then you can append any kind of values after the origin on checkbox change method.

Upvotes: 1

Related Questions