can you change the url of a link?

1

What happens is that I have a link already created from the beginning

<a href="/urlParaCambiar"> link

and then I mark a checkbox of several checkboxes and I want to modify the url of the link, adding the value of the checkbox to the URL of the link to send it from GET

asi:

<a href="/urlParaCambiar+"elvalorDelCheckMarcado""> link
    
asked by hubman 15.04.2017 в 05:39
source

2 answers

4

You can do that using Jquery

    $("#id").attr("href", "https://www.example.com/jquery");

Using Jquery and selecting the id of your "< a >" with $ ("") and placing attr ("href", "nuevaurl") you can change the url as you like

    
answered by 15.04.2017 в 05:55
3

You have several options to change the value of an attribute, more or less compatible with the various browsers, without need to use nothing but pure Javascript and hard .

Once you have located the element itself (using GetElementById( ) or in any other way), you can use:

  • X.attributes["href"] = "NUEVA_HREF" .
  • X.href = "NUEVA_HREF" .
  • X.setAttribute( "href", "NUEVA_HREF" ) .

A wide list of access methods is available in

DOM methods and properties that are for all implementations

next to the support in several browsers. It is not very up-to-date, but it can be useful to guide you.

    
answered by 15.04.2017 в 09:45