Jquery: How to select only within a selection?

2019-04-03 17:56发布

问题:

var parent = $("#jcontent");
var button1 = parent(".button1")

How to select .button1 knowing it is inside the parent while not reusing #jcontent?

I need to do this because I only want to pass the parent as parameter and to be able to cache it which is faster.

回答1:

Another alternative

var parent = $("#jcontent"); 
var button1 = $(".button1", parent) ;


回答2:

var button1 = parent.find(".button1");