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

  • Home
  • SEARCH
  • 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 9225715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:39:03+00:00 2026-06-18T04:39:03+00:00

I am trying to write a Javascript that sorts some paragraphs. Here’s a small

  • 0

I am trying to write a Javascript that sorts some paragraphs. Here’s a small snippit of the HTML that I am sorting:

<p>Brown, John, 2010, <a href="#">Link</a></p>

<p>Bush, C.A., 2010, <a href="#">Link</a>: More info.</p>

<p><br></p>
<h3><a name="c">C</a></h3>

<p>Caine, J.S., and Minor, S.A., 2010, <a href="#">Link</a>: More</p>

This Javascript is looking for the entries that contain “2010” (which are 3 out of the 4 paragraphs):

var paras = document.getElementsByTagName("p");
alert( paras.length );  // 4, which is what I expect!

for( i=0; i < paras.length ; i++ ) {
    var node0_text = paras[i].childNodes[0].nodeValue;

    if ( node0_text.indexOf('2010') ) {
        alert( node0_text ); // not returning everything that I expect it to.
    };
}

When I run this the first 2 entries (“Brown” and “Bush”) pop up in the alert box just as I expect they would. Then the script seems to die. It does not display the third (“Caine”) entry. What went wrong here? Thanks for any input.

A link to it: http://jsfiddle.net/Jrmy/6MP2W/5/

  • 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-18T04:39:05+00:00Added an answer on June 18, 2026 at 4:39 am

    The “Caine” entry is in the fourth paragraph. The script fails because the third paragraph has no text.

    This is the third paragraph:

    <p><br></p>
    

    The text is null so the if statement gets an exception for trying to access .indexOf().

    (edit — a good comment points out that it’s the <br> tag being checked for a value, but that’s null too.)

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

Sidebar

Related Questions

Alright... I'm trying to write some javascript code that will apply to an html
I'm trying to write a simple javascript function that will clone some html input
I'm trying to write a javascript function that adds some DOM nodes to the
I'm trying to write some JavaScript for my website that will select all the
I'm trying to write a small piece of Javascript that will sort through a
I am trying to write some JavaScript that calls a Web Service I've created.
I am trying to write some JavaScript that draws a line by dragging the
I'm trying to write some javascript that will grab the inner text of li
I'm trying to write some javascript to ensure that a table has lineNumber tr
I am trying to write some javascript that will automatically take text in a

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.