开发者

jQuery: Get id from selector which is inside a variable

I have a #pdfcontainer which is inside divs #main and #pdfmain. I'm using a variable, because I use the same div many times:

var $pdfcontainer = $('#main #pdfmain #pdfcontainer');

Inside the #pdfcontainer I have #delete which I want to access for various reasons. So how do I get it using the variable and without typing the whole $('#main ...') all over again? I don't just want to use selector $('#delete') because on my site it's much slower that way.

Thnx 开发者_如何转开发already!

  • Antti


Specify $pdfcontainer as context to your selector like this:

$("#delete", $pdfcontainer)

Make sure that you have only one item with unique ids, for example, you should have id #delete assigned to only one element.


$($pdfcontainer + " #delete") should work, if you declare your variable as a string var $pdfcontainer = "#id #id2 #id3";. Using the variable in place of the actual string doesn't mean you can't add more to the string.


$pdfcontainer.find('#delete');


try this..

$pdfcontainer.find('#delete'); 


you can use pdfcontainer.find("#delete) enjoy!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜