1

how can I concatenate the second line:

 var newLink = $(this).attr("id")

 $("section").load( newLink + "section > *"); // this is not working

newLink is the variable and "section > *" is the selector.thx

4
  • What is the value of newlinnk? Commented Mar 12, 2015 at 21:07
  • why a call to load()? Isn't that an Ajax method? Commented Mar 12, 2015 at 21:08
  • some link, like: index html, but it dosent matter because is going to change all the time... or does it? Commented Mar 12, 2015 at 21:09
  • @Noobest It matters. Because CSS selector might need # or maybe not in front. Commented Mar 12, 2015 at 21:11

1 Answer 1

1

You need to put space before "section", otherwise CSS selector is incorrect (assuming that there is child section tag within whatever tag newLink points to):

var newLink = $(this).attr("id")
$("section").load(newLink + " section > *");

Note, that you might want to prepend newLink with # if you want ID selector.

Sign up to request clarification or add additional context in comments.

3 Comments

also a "#" in front of newLink : $("section").load('#' + newLink + " section > *");
@jlowcs Right, I'm just not sure OP wants id selector, or something else. newLink can be div or something.
I just needed to add the space, so simple yet so difficult. Thx.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.