0

I'm new to JQuery and I noticed this line $('#DivID [type=checkbox]') and I was wondering if I can also find the select or option tags using the same method.

Update: I have a div that has more than more tag, I'm trying to get the DropDownList/Select that it's value's just changed.

Update2 I'm using InstaFilta a JQuery plugin that filter the content based on a customized attribute appended to my content tags. Below is a snippet for the function that do the same when working with CheckBoxes, and I'm trying to edit it to work with DropDownLists/Select controls.

var $ex10Checkboxes = $('#ex10 [type=checkbox]');

$ex10Checkboxes.on('change', function() {

    var checkedCategories = [];

    $ex10Checkboxes.each(function() {
        if ($(this).prop('checked')) {
            checkedCategories.push($(this).val());
        }
    });

    ex10.filterCategory(checkedCategories, true);
});

1 Answers1

1

You would find the option tags as follows:

$("#DivID option")

Likewise the select tags:

$("#DivID select")

You can then iterate over the returned objects to inspect the individual elements:

var foo = $("#DivID option");
var i;
for (i = 0; i < foo.length; i += 1) {
    console.log(foo[i].val()); //or whatever
}

To find the selected element you could check out this question:

$("#DivID option:selected")

I would suggest checking out the JQuery page on Selectors JQuery Selectors

Community
  • 1
  • 1
Ryder Brooks
  • 2,049
  • 2
  • 21
  • 29