0

I've been here and accordingly found out that this piece of code here

var node_exists=$(treeselector).find("li[id^='someid']");

where treeselector is the selector to the element within which the elements to be searched for are contained.This works perfectly fine.

However when in the id^='someid' part I try to change 'someid' to some variable which contains the id then it stops working.

var someid='someid'
var node_exists=$(treeselector).find("li[id^=someid]");

I also tried concatenating single quotes when the parameter is recieved in the function where this is fired. I think this might have to do with the double quotes surrounding the li[id^='someid'] part. Any idea as to how to make this work?

Cheers !!

Community
  • 1
  • 1
Ashwin
  • 1,190
  • 2
  • 10
  • 30

1 Answers1

1

Concatenate:

var someVar = 'id1';
var node_exists=$(treeselector).find("li[id^="+someVar+"]");
Kristian
  • 21,204
  • 19
  • 101
  • 176
  • Worked...now it sounds stupid....im a newbie sorry..will accept the answer as soon as i can – Ashwin Apr 06 '12 at 05:16
  • BTW, "[attribute=val]" is one of the slower (as in low performance) ways you can do a selection in jquery. you should make it a point use ID and class syntax where possible: li.someClassName or li#someIdName rather than by [attr=val] – Kristian Apr 06 '12 at 05:29