Arjang Arjang - 1 year ago 53
jQuery Question

Select all the elements within an element having an attribute set to a specific value

I have the followings defined :

var excludedFiltersPanel = $("#excludedFiltersPanel");
var includedfiltersPanel = $("#includedfiltersPanel");


where *Panel is just a div.

in
excludedFiltersPanel
there are some div's with attribute
data-iscorefilter="true"
e.g. :

<div id="filterPanel-LastName" class="filterPanel" data-iscorefilter="true">
<Some Stuff here!>
</div>


I am trying to get them and move them to includedfiltersPanel:

It seems neither of these is a correct syntax:


  • excludedFiltersPanel.('[data-iscorefilter="true"]')

  • excludedFiltersPanel.$('[data-iscorefilter="true"]')



1.What is the correct syntax?

2.How do I append them to
includedfiltersPanel
? (I know how to append a single item, but not sure what is the common good practice here, e.g. using for loop or some JQuery magic)

Answer Source

Since excludedFiltersPanel there are some div's with attribute data-iscorefilter="true"

Use .find()

Description: Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.

It would look like :

excludedFiltersPanel.find('[data-iscorefilter="true"]')