Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 936823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:22:29+00:00 2026-05-15T21:22:29+00:00

Script replaces rel attributes to class . Full code – http://jsbin.com/efozi3/8/ It doesn’t work

  • 0

Script replaces rel attributes to class.

Full code – http://jsbin.com/efozi3/8/

It doesn’t work for links, where used more than 2 values in rel.

An example – the first item:

<a class="s1" rel="t1 t2 t3" href="#">One</a>

First three <li> should become blue, but now only the first one does.

 <li class="t1">
     <strong>1</strong>
 </li>
 <li class="t2">
      <strong>2</strong>
 </li>
 <li class="t3">
      <strong>3</strong>
 </li>

This line doesn’t work as expected (supports maximum 2 values in rel):

return $('.' + elem.rel.replace(' ', ', .'));

You can edit code directly on http://jsbin.com/efozi3/8/edit/

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:22:29+00:00Added an answer on May 15, 2026 at 9:22 pm

    Believe it or not, Javascript’s replace function only replaces the first occurrence of the search text.
    To replace every occurrence, you need to pass a regex with the g (Global) flag.

    Change it to

    return $('.' + elem.rel.replace(/\s+/g, ', .'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

jsFiddle Full Code: http://jsfiddle.net/bvmdW/ I used jQuery Embedly to replace YouTube links with thumbnail
http://www.queness.com/post/328/a-simple-ajax-driven-website-with-jqueryphp I'm trying to get the above script to work, but with some changes.
How do I create a AutoHotkey-script which replaces my abbreviated network-username with my full
I have a Google Apps script which replaces placeholders in a copy of a
I'm writing a simple script that replaces two images. The first one swaps in
I have a ColdFusion script that does: <cfset content = replace(content,&##147;,,all)> Which replaces &147;
I have a script that generates a csv file using the following code: header('Content-type:
I have a Perl script that replaces any Us or Ns at the end
I'm using a script which replaces the usual file upload input with whatever image
I reduced a php script to the exact code necessary to solve a perplexing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.