- 4 months ago 19x
jQuery Question

Changing core TagHelpers with Javascript

I have

<a id="continue-link" asp-controller="Account" asp-action="Register" asp-route-id="1">Continue </a>

in my core application, that generate this html when compiled:

<a href="/Account/Register/1" id="continue-link">Continue </a>

How can i change
value from javascript? I tried with
but it's not recognized.


You have to change your href attribute in generated html.

You can achive this by geting your href attribute, split it into array, then change value in array and join it again into one string with separator and then replace href attribute in your a element.

Code example:

var $link = $('#continue-link');
var href = $link.attr('href').split('/');
href[3] = 4; //here you set your new asp-route-id value
$link.attr('href', href.join('/'));

Check this codepen to see how it work.