开发者

Save an element into a variable fail

开发者 https://www.devze.com 2023-04-12 02:31 出处:网络
I tried to save an element into a variable like this: var callID = 3; $active2 = $(\".paging a[rel=\'callID\']\");

I tried to save an element into a variable like this:

var callID = 3;
$active2 = $(".paging a[rel='callID']");

The class "paging" looks like this:

<div class="paging">
    <a href="#" rel="1">1</a>
    <a href="#" rel="2">2</a>
    <a href="#" rel="3">3</a>
</div>

But when I am consol.log($active2) there is only "[]" a empty bracket...so somethi开发者_运维知识库ng has to be wrong about this part:

$active2 = $(".paging a[rel='callID']");

Can someone help me to solve this problem?

-Thanks

Kind Regards


Try:

$active2 = $(".paging a[rel='" + callID + "']");

callID is the name of a variable, so in your examples you were literally looking for a anchor tag who had a rel attribute of callID.

Also, unrelated to your problem, don't forget to declare you $active2 variable somewhere.


callID is a variable. now you search for A with rel 'callID' not the value of callID

$active2 = $(".paging a[rel='"+callID+"']");
0

精彩评论

暂无评论...
验证码 换一张
取 消