Stephen's dev blog

jQuery wildcard selectors

Posted on: 5 August, 2008

UPDATE: The below method no longer works! Go here to see a tested, working method: http://ropox.net/archives/1081

This is the first tutorial on my blog. We’re going to start with something simple and it’s only useful if you use jQuery.

When I started using jQuery I found it hard to find information on using wildcards when selecting DOM elements.

After a while you get to understand that jQuery allows the use of regular expressions in a lot of places, I.E. when selecting like this:

$('#myElement').html();

So with this in mind, you can use \\S* to make wildcard selections, I.E.:

$('#myEle\\S*').each();

Stephen.

8 Responses to "jQuery wildcard selectors"

Thanks for this post, just what I’ve been looking for. Many of my pages had validation errors because of duplicate IDs (for example the user image layer on comment pages).

Knowing this is possible allows me to simply attach a random token to the IDs so make them unique, but still be able to select the boxes without tracing the token.

Hi Rob,

Thanks for the comment and I’m glad you found this useful.

Myself and a number of my colleagues have run into this same situation and found this to be a perfect solution.

Stephen.

Nice find! I didnt even know you could use regex on selectors!

Thanks man

Hi Lex,

Glad you found this useful! 🙂

Stephen.

[…] Flex 3 DataGrid double click eventjQuery wildcard selectorsFlex getting selected RadioButton valuejQuery loading remote/external javascript files using […]

Hi, i see your regex! Its nice to know you use those! But i have a problem, im not sure on how to use the regex.

i need to search for all nested li`s within a ul ( where any li can have it`s own ul with li`s) but i cant get it right tho..

What would be the query or regex for this?

#navigation * li doesnt work.. so im kinda not sure what to do now

Hi James,

You can achieve what you want using .find().

$('#IDofUL').find('li').each(function()
{
    // do something with li
});

Stephen.

Comments are closed.


  • Patrick: I changed my code, but now I have another problem: Fatal error: Call to a member function isAvailable() on a non-object in /var/www/vhost/web/shopA
  • Stephen Gray: Hi Patrick, That first error is my fault. I had the method name for the refund() method as void() as I had copied the code from the other method!
  • Patrick: Hi Stephen, thanks for sharing your knowledge about creating a custom payment module. I need an extension for magento to handle a credit card payme

Categories

%d bloggers like this: