1

I might be overlooking the obvious but I am trying to do a basic string concatenation and it does not seem to play to well

I have the following variables

var plug = "myPlug"; var pdiv = "<p></p>"; var tab_id = "#someID"; $(tab_id + "p:contains('" + plug + "')").parent().next().append(pdiv); 

For some reason tab_id does not get substituted. Any help would be appreciated.

1
  • 2
    I suspect you want a space before the "p" in "p:contains(...)". Commented Sep 10, 2013 at 18:17

3 Answers 3

2

You need to leave a space between #someID and p:contains. Concatenation does not add spaces by itself.

You need to use:

$(tab_id + " p:contains('" + plug + "')").parent().next().append(pdiv); ^ give extra space here 
Sign up to request clarification or add additional context in comments.

Comments

2

because you are looking for

("#someIDp:contains....") ^^ No space 

Comments

1

It looks like you're missing a space. Currently your selector will evaluate to:

$("#someIDp:contains('myPlug')") 

which... doesn't look right. Try adding a space after the ID and before the child p element:

$(tab_id + " p:contains('" + plug + "')") 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.