Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
How can I make this jQuery script more efficient?
Old 12-13-2011, 08:18 AM How can I make this jQuery script more efficient?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
Hi all

I have an image with a class "right-40"
Code:
<img class="right-40" src=".." alt=".." />
I need to use jQuery to find any image on the page with
the class "right-40", remove the class from the image,
and create a wrapper DIV around the image with class "right-40".
Code:
<div class="right-40"><img src=".." alt=".." /></div>
Easy peasy, right?

BUT

There could also be other images on the page with similar
class names like "right-45", "right-65" etc.

Rather than writing out every possible class name into a conditional
statement, how can I get jQuery to look for any class names
that fit the patter [right-*]

I am guessing there might be a bit of REGEX that would do the job?
Or is there an even more efficient way to get jQuery to parse the document?

Help appreciated.
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE
TWD is online now
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-13-2011, 07:30 PM Re: How can I make this jQuery script more efficient?
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
You're right, its regex but it's not supported by jquery natively (maybe in the new version). But here's a filter you could use:

http://james.padolsey.com/javascript...or-for-jquery/

and selector would be something like

Code:
$("img:regex(class, right-[0-9+])")
i suck at regex so that's a guess there, you'll have the get help from a better regex expert
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 12-14-2011, 07:47 PM Re: How can I make this jQuery script more efficient?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
You could probably make due with the "starts with" selector.
http://api.jquery.com/attribute-starts-with-selector/
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-14-2011, 08:13 PM Re: How can I make this jQuery script more efficient?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
Quote:
Originally Posted by lizciz View Post
You could probably make due with the "starts with" selector.
http://api.jquery.com/attribute-starts-with-selector/
Thanks. That seems like just what I need.
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE
TWD is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to How can I make this jQuery script more efficient?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13242 seconds with 12 queries