25

Hi I have a select like:

<select id="item_OfficeUserId" class="dropdownauditor" name="item.OfficeUserId" invoicelineid="33">

In jQuery I can get it by its class:

$(".dropdownauditor")

Is there a way to get it based on its class and it attribute invoicelineid="33" as well?

There will be more than one with class="dropdownauditor". I want to get the selected item of the particular select. I was using:

$(".dropdownauditor").change(function () {
    $(".dropdownauditor option:selected").each(function () {
    ...
    }
}

But this is running through the second part twice. ie. It tis then finding the selected for every select with class="dropdownauditor" Is is possible to only find only one with invoicelineid="33"?

AnonyMouse
  • 18,108
  • 26
  • 79
  • 131

1 Answers1

66
$(".dropdownauditor[invoicelineid='33']")

Using the attribute equals selector.

Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307
  • Works in all browsers. I was told that syntax i s browser dependent. – AnonyMouse Oct 05 '11 at 01:52
  • 1
    @AnonyMouse: Hmm, I think you're okay. However, using arbitrary attributes is not recommended especially with `data-*` attributes around. – Andrew Whitaker Oct 05 '11 at 01:54
  • I'm new to those. Does that mean to just add data-* like data-invoicelineid? – AnonyMouse Oct 05 '11 at 01:55
  • 1
    @AnonyMouse: Yep! They are HTML5 but *shouldn't* cause problems in older browsers. Here's a good question on the subject: http://stackoverflow.com/questions/2412947/do-html5-custom-data-attributes-work-in-ie-6# – Andrew Whitaker Oct 05 '11 at 01:57