1

I work in Laravel and have a page http://localhost:8000/tours/ and jquery script on it. In the script, there is a code:

var i = 1;
$('<li>').append('<a href='load_page_"+i+"'>"+i+"</a>');

after code has worked, I have a link on the page:

<a href='tours/load_page_1'>1</a>

but I want it to be:

<a href='load_page_1'>1</a>

how can I achive that?

PS. My question is not how to modify href (.attr('href')), but how to make the link to be I want it to be when adding it as html via append/prepend/after/before etc (or explanation why it's impossible).

Sergej Fomin
  • 1,822
  • 3
  • 24
  • 42
  • Possible duplicate of [How to change the href for a hyperlink using jQuery](https://stackoverflow.com/questions/179713/how-to-change-the-href-for-a-hyperlink-using-jquery) – Ousmane D. Oct 27 '17 at 19:56
  • You likely DO have href=“load_page_1” which when hovered will show tours/load_page_1 because that is what it will go to regardless. You possibly want ../load_page1 – mplungjan Oct 27 '17 at 20:06

1 Answers1

2

It sounds like what you're wanting is a link to http://localhost:8000/load_page_1, but instead are getting a link to http://localhost:8000/tours/load_page_1.

You should be able to get the link that you're wanting by changing your append line to $('<li>').append('<a href='../load_page_"+i+"'>"+i+"</a>');

The ../ part tells it to go one folder up in the directory tree and link to the specified page there.

Herohtar
  • 5,347
  • 4
  • 31
  • 41
  • thank you! that's the answer. Though I understand I have another problem. When I am then send an ajax-request (when clicking on the link) it send the request to '/tours/load_page1' instead of '/load_page1/'. Did you encounter such a problem before? – Sergej Fomin Oct 27 '17 at 20:12
  • My guess would be that it is related to this issue... I can't say for sure without seeing code. If you can't figure it out, you can always post another question on here. – Herohtar Oct 27 '17 at 20:15