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 7994159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:03:43+00:00 2026-06-04T14:03:43+00:00

I have a simple HTML template that’s used multiple times across the document. It’s

  • 0

I have a simple HTML template that’s used multiple times across the document. It’s essentially the following div element wrapping around several p elements and another div element with the class button. For visualization purposes, here’s an example:

<div class="content">    
    <p>First paragraph</p>
    <p>Second paragraph</p>

    <div><a class="button" href="http://www.apple.com/ipad/">Change me jQuery!</a></div>
</div>

<div class="content">    
    <p>First paragraph</p>
    <p>Second paragraph</p>

    <div><a class="button" href="http://www.apple.com/iphone/">Change me jQuery!</a></div>
</div>

Now, the users who will use this template to publish content on the site not always will use the same exact url in that anchor tag, but I do know exactly which ones they can use. So what I’m trying to do with my code is the following:

  1. Once the content has been published and the anchor tag given a url
    address, I want to check that address and see if there’s a specific
    word in it. If that word is found, then change the anchor text to something of my choice.
  2. Do the same again but this time checking for a different word in the url string.

Here’s what I’ve written:

$('.content').each(function () {
    var $this = $(this),
        $findP = $this.find('p');

    if ($findP.length > 2) {
        // Run some code
    } else if ( ($findP.length <= 2) && ($('a[href*="ipad"]')) ) {
        $this.find('a.button').text('Visit iPad site');
    } else if ( ($findP.length <= 2) && ($('a[href*="iphone"]')) ) {
        $this.find('a.button').text('Visit iPhone site');
    }
});​

Issues:

  • Both anchor tags’ text only change to the string of text that I’ve written in the first else if statement inside the .text() jQuery method. In my example here, the first anchor tag should take the text “Visit iPad site” while the second one should be “Visit iPhone site”. Here’s a working fiddle of this example: http://jsfiddle.net/vj4xZ/1/

I’m guessing the issue is here that once the first element is found, all anchor tags are assigned what’s in the .text() method and the code stops right there without looking for the what’s in the second else if statement. If that’s the case, or the issue at hand is something else, then how can I get that to working properly? Any help with this will be appreciated. Thank you for your time!

  • 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-06-04T14:03:44+00:00Added an answer on June 4, 2026 at 2:03 pm

    http://jsfiddle.net/zerkms/vj4xZ/2/

    You need to change your conditions to this:

    } else if ( ($findP.length <= 2) && ($this.find('a[href*="ipad"]').length) ) {
    

    $('a[href*="ipad"]') – means – if there is an anchor with ipad in href somewhere in the document

    What I changed – is limited searching the anchor only by current element with $this.find()

    You may also use $('a[href*="ipad"]', $this) instead, it would do the same work

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple html page with a div element in it. The innerHTML
I have simple template that's html mostly and then pulls some stuff out of
I have simple html code that plays YouTube video after click on the image:
I have simple HTML page with svg like this: <div id=plan> <svg xmlns=http://www.w3.org/2000/svg version=1.1>
I have following simple HTML and JS code. When User selects Italian Language option
i have this simple html: <div id="tree"> <div class="roi"> <ul> <li>text1</li> <li>text2</li> <li>text3 <ul>
I have a simple html site.I want to change the language for that based
I have made a simple HTML for my ebay template and I wanted to
I have a simple animation on my rails site that pop's a div (with
I have a simple erb template that pulls information from a (Grit) git repository.

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.