Wednesday, 15 May 2013

javascript - How to find and edit a elements' href values without losing query params? -



javascript - How to find and edit a elements' href values without losing query params? -

how find element <a> in page contain href attr /dailytickets/front/user.form.php, alter /dailytickets/front/contacts.form.php?

notice want maintain url query parameters (id) next path (user.form.php). example, changing this:

<a id="user_648_648" href="/dailytickets/front/user.form.php?id=648">conseilleruser</a>

to this:

<a id="user_648_648"href="/dailytickets/front/contacts.form.php?id=648">conseilleruser</a>

i'm starting this, don't know how end it:

$('a[href*="dailytickets/front/user.form.php"]').each(function () { if ($(this).children().length == 0) { ........... } });

there's no need loop, jquery interally you, , using selector outright alter , elements match:

$('a[href*="dailytickets/front/user.form.php"]').attr('href', function(i,href) { homecoming href.replace('user.form.php', 'contacts.form.php'); });

javascript jquery html

No comments:

Post a Comment