InTry
InTry

Reputation: 1169

Select cached element with dynamic attribute

How it would be possible to cache and select element looks like this?

".myClass[data-list='2']";

This works:

var listNo = "2";

    ".myClass[data-list='" + listNo + "']";

But this is what I am trying and I can't make it works:

var listNo = "2", 
myClass = $('.myClass');

    myClass + "[data-list='" + listNo + "']"

and this is what Firebug is saying to me:

Error: Syntax error, unrecognized expression: [object Object][data-list='02']

Upvotes: 0

Views: 100

Answers (1)

0x6C77
0x6C77

Reputation: 939

I think you are looking for filter, for example:

myClass.filter("[data-list='" + listNo + "']")

Upvotes: 1

Related Questions