[jQuery] Re: jQuery select where attribute ID less than
Well its for a chat box and I want to remove old messages as new messages come in, so that there are 20 messages being shown at any one time, using = works perfectly if you add 1 new message because it selects the last message ID and subtracts 20, but if you add 2 messages then the first message will stay and the second message will disappear. Source code: http://www.forsakenrealms.co.cc/chat/?user=test On Aug 31, 11:01 pm, Michael Geary m...@mg.to wrote: Can you give us a hint what your DOM elements look like? For example, are these ID attributes in ascending order in the DOM? That would allow you to use a very fast binary search. If they are in an undetermined order then you're pretty much stuck with looping through them - but with thousands of them I would use a for loop rather than .each(). Or as Josh suggested, do something on the server. But it's hard to make any recommendations without knowing more about what you're doing. -Mike From:Namir Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50,Namirnamiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
Then use indexes from the parent and :lt ( http://docs.jquery.com/Selectors/lt#index) aquaone On Tue, Sep 1, 2009 at 04:07, Namir namiras...@hotmail.com wrote: Well its for a chat box and I want to remove old messages as new messages come in, so that there are 20 messages being shown at any one time, using = works perfectly if you add 1 new message because it selects the last message ID and subtracts 20, but if you add 2 messages then the first message will stay and the second message will disappear. Source code: http://www.forsakenrealms.co.cc/chat/?user=test On Aug 31, 11:01 pm, Michael Geary m...@mg.to wrote: Can you give us a hint what your DOM elements look like? For example, are these ID attributes in ascending order in the DOM? That would allow you to use a very fast binary search. If they are in an undetermined order then you're pretty much stuck with looping through them - but with thousands of them I would use a for loop rather than .each(). Or as Josh suggested, do something on the server. But it's hard to make any recommendations without knowing more about what you're doing. -Mike From:Namir Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50,Namirnamiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
I tried using this $(span.message[id=+old_messages+]:lt(100)).hide (slide, {direction: up}, 2000); but it doesnt seem to be working correctly On Sep 1, 7:07 pm, aquaone aqua...@gmail.com wrote: Then use indexes from the parent and :lt (http://docs.jquery.com/Selectors/lt#index) aquaone On Tue, Sep 1, 2009 at 04:07, Namir namiras...@hotmail.com wrote: Well its for a chat box and I want to remove old messages as new messages come in, so that there are 20 messages being shown at any one time, using = works perfectly if you add 1 new message because it selects the last message ID and subtracts 20, but if you add 2 messages then the first message will stay and the second message will disappear. Source code:http://www.forsakenrealms.co.cc/chat/?user=test On Aug 31, 11:01 pm, Michael Geary m...@mg.to wrote: Can you give us a hint what your DOM elements look like? For example, are these ID attributes in ascending order in the DOM? That would allow you to use a very fast binary search. If they are in an undetermined order then you're pretty much stuck with looping through them - but with thousands of them I would use a for loop rather than .each(). Or as Josh suggested, do something on the server. But it's hard to make any recommendations without knowing more about what you're doing. -Mike From:Namir Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50,Namirnamiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
wouldnt work, even if I set the index to count the number of messages and subtract 20 and index those as sometimes there may be missing ID's as they may have been deleted. On Sep 1, 9:59 pm, James james.gp@gmail.com wrote: Try using just: $(span.message:lt(100)) If you want to remove elements that are on the bottom, you may want to use gt() instead of lt(). For example, suppose your code looks like: span class=message id=msg5test/span // index 0 span class=message id=msg4test/span // index 1 span class=message id=msg3test/span // index 2 span class=message id=msg2test/span // index 3 span class=message id=msg1test/span // index 4 Doing: $(span.message:gt(2)).hide(); will hide: span class=message id=msg2test/span // index 3 span class=message id=msg1test/span // index 4 because they have index greater-than 2. On Sep 1, 10:16 am, Namir namiras...@hotmail.com wrote: I tried using this $(span.message[id=+old_messages+]:lt(100)).hide (slide, {direction: up}, 2000); but it doesnt seem to be working correctly On Sep 1, 7:07 pm, aquaone aqua...@gmail.com wrote: Then use indexes from the parent and :lt (http://docs.jquery.com/Selectors/lt#index) aquaone On Tue, Sep 1, 2009 at 04:07, Namir namiras...@hotmail.com wrote: Well its for a chat box and I want to remove old messages as new messages come in, so that there are 20 messages being shown at any one time, using = works perfectly if you add 1 new message because it selects the last message ID and subtracts 20, but if you add 2 messages then the first message will stay and the second message will disappear. Source code:http://www.forsakenrealms.co.cc/chat/?user=test On Aug 31, 11:01 pm, Michael Geary m...@mg.to wrote: Can you give us a hint what your DOM elements look like? For example, are these ID attributes in ascending order in the DOM? That would allow you to use a very fast binary search. If they are in an undetermined order then you're pretty much stuck with looping through them - but with thousands of them I would use a for loop rather than .each(). Or as Josh suggested, do something on the server. But it's hard to make any recommendations without knowing more about what you're doing. -Mike From:Namir Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50,Namirnamiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
It doesn't matter if they're missing IDs. You don't need the IDs. (Also, IDs cannot begin with a number. It's not valid.) All you need to know is how many new messages you received on your latest update (to determine how many old ones to remove), and your maximum number of messages to display at once. That is enough info to do what you want. On Sep 1, 11:07 am, Namir namiras...@hotmail.com wrote: wouldnt work, even if I set the index to count the number of messages and subtract 20 and index those as sometimes there may be missing ID's as they may have been deleted. On Sep 1, 9:59 pm, James james.gp@gmail.com wrote: Try using just: $(span.message:lt(100)) If you want to remove elements that are on the bottom, you may want to use gt() instead of lt(). For example, suppose your code looks like: span class=message id=msg5test/span // index 0 span class=message id=msg4test/span // index 1 span class=message id=msg3test/span // index 2 span class=message id=msg2test/span // index 3 span class=message id=msg1test/span // index 4 Doing: $(span.message:gt(2)).hide(); will hide: span class=message id=msg2test/span // index 3 span class=message id=msg1test/span // index 4 because they have index greater-than 2. On Sep 1, 10:16 am, Namir namiras...@hotmail.com wrote: I tried using this $(span.message[id=+old_messages+]:lt(100)).hide (slide, {direction: up}, 2000); but it doesnt seem to be working correctly On Sep 1, 7:07 pm, aquaone aqua...@gmail.com wrote: Then use indexes from the parent and :lt (http://docs.jquery.com/Selectors/lt#index) aquaone On Tue, Sep 1, 2009 at 04:07, Namir namiras...@hotmail.com wrote: Well its for a chat box and I want to remove old messages as new messages come in, so that there are 20 messages being shown at any one time, using = works perfectly if you add 1 new message because it selects the last message ID and subtracts 20, but if you add 2 messages then the first message will stay and the second message will disappear. Source code:http://www.forsakenrealms.co.cc/chat/?user=test On Aug 31, 11:01 pm, Michael Geary m...@mg.to wrote: Can you give us a hint what your DOM elements look like? For example, are these ID attributes in ascending order in the DOM? That would allow you to use a very fast binary search. If they are in an undetermined order then you're pretty much stuck with looping through them - but with thousands of them I would use a for loop rather than .each(). Or as Josh suggested, do something on the server. But it's hard to make any recommendations without knowing more about what you're doing. -Mike From:Namir Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50,Namirnamiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
Try using just: $(span.message:lt(100)) If you want to remove elements that are on the bottom, you may want to use gt() instead of lt(). For example, suppose your code looks like: span class=message id=msg5test/span // index 0 span class=message id=msg4test/span // index 1 span class=message id=msg3test/span // index 2 span class=message id=msg2test/span // index 3 span class=message id=msg1test/span // index 4 Doing: $(span.message:gt(2)).hide(); will hide: span class=message id=msg2test/span // index 3 span class=message id=msg1test/span // index 4 because they have index greater-than 2. On Sep 1, 10:16 am, Namir namiras...@hotmail.com wrote: I tried using this $(span.message[id=+old_messages+]:lt(100)).hide (slide, {direction: up}, 2000); but it doesnt seem to be working correctly On Sep 1, 7:07 pm, aquaone aqua...@gmail.com wrote: Then use indexes from the parent and :lt (http://docs.jquery.com/Selectors/lt#index) aquaone On Tue, Sep 1, 2009 at 04:07, Namir namiras...@hotmail.com wrote: Well its for a chat box and I want to remove old messages as new messages come in, so that there are 20 messages being shown at any one time, using = works perfectly if you add 1 new message because it selects the last message ID and subtracts 20, but if you add 2 messages then the first message will stay and the second message will disappear. Source code:http://www.forsakenrealms.co.cc/chat/?user=test On Aug 31, 11:01 pm, Michael Geary m...@mg.to wrote: Can you give us a hint what your DOM elements look like? For example, are these ID attributes in ascending order in the DOM? That would allow you to use a very fast binary search. If they are in an undetermined order then you're pretty much stuck with looping through them - but with thousands of them I would use a for loop rather than .each(). Or as Josh suggested, do something on the server. But it's hard to make any recommendations without knowing more about what you're doing. -Mike From:Namir Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50,Namirnamiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
Thats a very smart way of doing it. Thanks a lot. Also why is it invalid to start an ID as a number? I'm not receiving any errors by doing it. Should I instead set a custom attribute called msg_id and use that? On Sep 1, 10:21 pm, James james.gp@gmail.com wrote: It doesn't matter if they're missing IDs. You don't need the IDs. (Also, IDs cannot begin with a number. It's not valid.) All you need to know is how many new messages you received on your latest update (to determine how many old ones to remove), and your maximum number of messages to display at once. That is enough info to do what you want. On Sep 1, 11:07 am, Namir namiras...@hotmail.com wrote: wouldnt work, even if I set the index to count the number of messages and subtract 20 and index those as sometimes there may be missing ID's as they may have been deleted. On Sep 1, 9:59 pm, James james.gp@gmail.com wrote: Try using just: $(span.message:lt(100)) If you want to remove elements that are on the bottom, you may want to use gt() instead of lt(). For example, suppose your code looks like: span class=message id=msg5test/span // index 0 span class=message id=msg4test/span // index 1 span class=message id=msg3test/span // index 2 span class=message id=msg2test/span // index 3 span class=message id=msg1test/span // index 4 Doing: $(span.message:gt(2)).hide(); will hide: span class=message id=msg2test/span // index 3 span class=message id=msg1test/span // index 4 because they have index greater-than 2. On Sep 1, 10:16 am, Namir namiras...@hotmail.com wrote: I tried using this $(span.message[id=+old_messages+]:lt(100)).hide (slide, {direction: up}, 2000); but it doesnt seem to be working correctly On Sep 1, 7:07 pm, aquaone aqua...@gmail.com wrote: Then use indexes from the parent and :lt (http://docs.jquery.com/Selectors/lt#index) aquaone On Tue, Sep 1, 2009 at 04:07, Namir namiras...@hotmail.com wrote: Well its for a chat box and I want to remove old messages as new messages come in, so that there are 20 messages being shown at any one time, using = works perfectly if you add 1 new message because it selects the last message ID and subtracts 20, but if you add 2 messages then the first message will stay and the second message will disappear. Source code:http://www.forsakenrealms.co.cc/chat/?user=test On Aug 31, 11:01 pm, Michael Geary m...@mg.to wrote: Can you give us a hint what your DOM elements look like? For example, are these ID attributes in ascending order in the DOM? That would allow you to use a very fast binary search. If they are in an undetermined order then you're pretty much stuck with looping through them - but with thousands of them I would use a for loop rather than .each(). Or as Josh suggested, do something on the server. But it's hard to make any recommendations without knowing more about what you're doing. -Mike From:Namir Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50,Namirnamiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
*http://www.w3.org/TR/html4/types.html#type-id ID* and *NAME* tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). On Tue, Sep 1, 2009 at 14:44, Namir namiras...@hotmail.com wrote: Thats a very smart way of doing it. Thanks a lot. Also why is it invalid to start an ID as a number? I'm not receiving any errors by doing it. Should I instead set a custom attribute called msg_id and use that? On Sep 1, 10:21 pm, James james.gp@gmail.com wrote: It doesn't matter if they're missing IDs. You don't need the IDs. (Also, IDs cannot begin with a number. It's not valid.) All you need to know is how many new messages you received on your latest update (to determine how many old ones to remove), and your maximum number of messages to display at once. That is enough info to do what you want. On Sep 1, 11:07 am, Namir namiras...@hotmail.com wrote: wouldnt work, even if I set the index to count the number of messages and subtract 20 and index those as sometimes there may be missing ID's as they may have been deleted. On Sep 1, 9:59 pm, James james.gp@gmail.com wrote: Try using just: $(span.message:lt(100)) If you want to remove elements that are on the bottom, you may want to use gt() instead of lt(). For example, suppose your code looks like: span class=message id=msg5test/span // index 0 span class=message id=msg4test/span // index 1 span class=message id=msg3test/span // index 2 span class=message id=msg2test/span // index 3 span class=message id=msg1test/span // index 4 Doing: $(span.message:gt(2)).hide(); will hide: span class=message id=msg2test/span // index 3 span class=message id=msg1test/span // index 4 because they have index greater-than 2. On Sep 1, 10:16 am, Namir namiras...@hotmail.com wrote: I tried using this $(span.message[id=+old_messages+]:lt(100)).hide (slide, {direction: up}, 2000); but it doesnt seem to be working correctly On Sep 1, 7:07 pm, aquaone aqua...@gmail.com wrote: Then use indexes from the parent and :lt ( http://docs.jquery.com/Selectors/lt#index) aquaone On Tue, Sep 1, 2009 at 04:07, Namir namiras...@hotmail.com wrote: Well its for a chat box and I want to remove old messages as new messages come in, so that there are 20 messages being shown at any one time, using = works perfectly if you add 1 new message because it selects the last message ID and subtracts 20, but if you add 2 messages then the first message will stay and the second message will disappear. Source code:http://www.forsakenrealms.co.cc/chat/?user=test On Aug 31, 11:01 pm, Michael Geary m...@mg.to wrote: Can you give us a hint what your DOM elements look like? For example, are these ID attributes in ascending order in the DOM? That would allow you to use a very fast binary search. If they are in an undetermined order then you're pretty much stuck with looping through them - but with thousands of them I would use a for loop rather than .each(). Or as Josh suggested, do something on the server. But it's hard to make any recommendations without knowing more about what you're doing. -Mike From:Namir Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50,Namir namiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
Just for the record, ignoring performance and the invalid IDs, this could be done with filter(): $('span.class').filter(function(){ return this.id y; }); cheers, - ricardo On Aug 31, 6:57 pm, aquaone aqua...@gmail.com wrote: indeed. there's gotta be a better solution than this. if you can't control it and insist on using this method, $(span.class).each(function(){if($(this).attr('id')x){//do something}}); The performance on that will be crap. Please find an alternate solution e.g. .is(':gt'+x) aquaone On Mon, Aug 31, 2009 at 14:47, Josh Nathanson joshnathan...@gmail.comwrote: Any chance of doing what you need to do on the server, rather than the client? Are you stuck with the naming convention you're using, or can you name the spans a little differently or give them different class names to allow for better selection criteria? Given your current situation you'd have to loop through each span as Aquaone said, but I bet you might be able to think of a different way to approach the problem. -- Josh -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Namir Sent: Monday, August 31, 2009 2:33 PM To: jQuery (English) Subject: [jQuery] Re: jQuery select where attribute ID less than Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50, Namir namiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50, Namir namiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50, Namir namiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
Any chance of doing what you need to do on the server, rather than the client? Are you stuck with the naming convention you're using, or can you name the spans a little differently or give them different class names to allow for better selection criteria? Given your current situation you'd have to loop through each span as Aquaone said, but I bet you might be able to think of a different way to approach the problem. -- Josh -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Namir Sent: Monday, August 31, 2009 2:33 PM To: jQuery (English) Subject: [jQuery] Re: jQuery select where attribute ID less than Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50, Namir namiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
indeed. there's gotta be a better solution than this. if you can't control it and insist on using this method, $(span.class).each(function(){if($(this).attr('id')x){//do something}}); The performance on that will be crap. Please find an alternate solution e.g. .is(':gt'+x) aquaone On Mon, Aug 31, 2009 at 14:47, Josh Nathanson joshnathan...@gmail.comwrote: Any chance of doing what you need to do on the server, rather than the client? Are you stuck with the naming convention you're using, or can you name the spans a little differently or give them different class names to allow for better selection criteria? Given your current situation you'd have to loop through each span as Aquaone said, but I bet you might be able to think of a different way to approach the problem. -- Josh -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Namir Sent: Monday, August 31, 2009 2:33 PM To: jQuery (English) Subject: [jQuery] Re: jQuery select where attribute ID less than Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50, Namir namiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] Re: jQuery select where attribute ID less than
Can you give us a hint what your DOM elements look like? For example, are these ID attributes in ascending order in the DOM? That would allow you to use a very fast binary search. If they are in an undetermined order then you're pretty much stuck with looping through them - but with thousands of them I would use a for loop rather than .each(). Or as Josh suggested, do something on the server. But it's hard to make any recommendations without knowing more about what you're doing. -Mike From: Namir Still how would I do it with an each? I'd still need to select all the ones with an attribute of less than x, and it would be stupid to loop it from 1 to whatever as x can reach thousands. Do you have any other suggestions as to how I could do this? On Aug 31, 9:58 pm, aquaone aqua...@gmail.com wrote: id will be a string. AFAIK there's no built-in to parse it as a number and compare. you'd either have to .each() it or find another means of accomplishing what you are trying to do. aquaone On Mon, Aug 31, 2009 at 13:50, Namir namiras...@hotmail.com wrote: How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than