I found this code to change the url depending on which checkbox is selected here: Change href depending on checkboxes But I need to go one step before or replace the url instead add/push on the existing url. Like I'm on www.katana.com/e-bikes/ and I need to go to https://ift.tt/31V3BTS not want to stay on e-bikes and continue pushing the url.
I don't know if I have to change the push method or the problem is the "this" selector that adds the existing url.
Thank you so much!!!
var one ="111";
var two ="222";
var three ="333";
$('body').append('<a href=\"' + one + "," + two + "," + three + '\">link</a>'); //this is the default value
$('.checkbox').change(function() {
var href = "";
if ($('#one').is(':checked')) {
href = one;
}
if ($('#two').is(':checked')) {
href += (href != "") ? "," + two : two;
}
if ($('#three').is(':checked')) {
href += (href != "") ? "," + three : three;
}
$("a").attr("href", href);
});
Aucun commentaire:
Enregistrer un commentaire