Search code examples
jqueryinputhref

How do I add a string value of an href using jquery?


I have a input button that has an href. I need to add a string after the last / in the href from an input text box. How can this get accomplish using jquery? Here is the code:

//This is the Search Button
$('#switch-fighter-search-button-link').attr("href","/fighters/search/");

//This is the Input box
var sft = $('$switch-fighter-text').val();

Solution

  • $('#switch-fighter-search-button-link').attr("href","/fighters/search/" + $('$switch-fighter-text').val());