Dave
Dave

Reputation: 3882

Jquery with large/numerous items in selector cause error on IE8

I am trying to run a selector that has a large number of element ids to match but in IE8 i keep getting the error: object doesnt support this property or method.

The jquery is like this:

var elements = $('#182,#183,#184,#185,#211,#212,#213,#214,#220,#221,
#222,#223,#225,#226,#227,#228,#234,#241,#242,#243,#244,
#245,#246,#247,#248,#250,#251,#252,#253,#256,#257,#258,#259,#260');

The actual query is actually longer and the ids are not sequential. I have broken up the list into smaller parts and run each part separately. All of the smaller selectors run fine.

I was wondering if there is a way i could use one selector?

As Requested here is an example of the markup but there is hundreds of rows in reality:

<table id="ListTable">
<tbody>
<tr id="1" style="display: none;"></tr>
<tr id="2" style="display: none;"></tr>
<tr id="3" style="display: none;"></tr>
<tr id="4" style="display: none;"></tr>
<tr id="95" style="display: none;"></tr>
<tr id="5" style="display: none;"></tr>
<tr id="6" style="display: none;"></tr>
<tr id="7" style="display: none;"></tr>
<tr id="8" style="display: none;"></tr>
<tr id="9" style="display: none;"></tr>
<tr id="10" style="display: none;"></tr>
<tr id="11" style="display: none;"></tr>
<tr id="82" style="display: none;"></tr>
<tr id="83" style="display: none;"></tr>
<tr id="84" style="display: none;"></tr>
<tbody>
</table>

Upvotes: 0

Views: 332

Answers (1)

corroded
corroded

Reputation: 21574

put a class on each of those elements with ids(btw don't use ids with just numbers. make them a bit more descriptive and just parse them with substring) and call that class instead so you'll get an array of those elements:

$(".classname")

say you wanted to select:

<input id="#example_182" class="example" />
<input id="#example_125" class="example" />
<input id="#example_252" class="example" />
<input id="#example_183" class="example" />
<input id="#example_345" class="example" />
<input id="#example_456" class="example" />

you can then select them all using:

$(".example")

then if you wanted to get their ids loop through example and then do a substring

$(".example").each(function(ex) {
   myid = $(this).attr("id").substring(8)
})

*note, you better check the documentation for each, im not actually sure that's the syntax

Upvotes: 2

Related Questions