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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:11:16+00:00 2026-06-14T18:11:16+00:00

I am trying to write some Javascript to hide some elements that contain only

  • 0

I am trying to write some Javascript to hide some elements that contain only carriage returns. I appreciate that the correct way to solve this problem would be to stop these elements being created, but unfortunately that is not possible in this instance. I am trying to user a regular expression to search for the unwanted elements but am not having much luck. The function I have written is as follows:

function HideEmptyP()
{

    var patt = (\\r)
    for(var i = 0;i<desc[i].length;i++);
    {
    var desc[i] = document.getElementsByClassName('sitspagedesc');
    var result[i] = patt.test(desc[i]);
        if (result[i] == true)
            {
            desc[i].style.display='none';
            }
        else
            {
            alert("No Match!");
            }
    }

The error I’m getting in the Web Console is ‘Syntax Error: Illegal Character’.

Grateful for any ideas on how to solve this.

Thanks in advance.

  • 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-14T18:11:17+00:00Added an answer on June 14, 2026 at 6:11 pm

    I am trying to write some Javascript to hide some elements that contain only carriage returns.

    There’s no need for a regular expression for that, just compare the element’s innerHTML property to "\\r", e.g.:

    if (demo[i].innerHTML === "\\r") {
        // Remove it
    }
    

    But beware that some browsers may transform a single carriage return. You might want to check for "\\r", "\\n", and just a space. To do that, you might want to use a regular expression.

    Your regular expression literal ((\\r)) is just completely invalid, it’s worth reading up on them to learn the correct syntax. To write a regular expression literal in JavaScript, you use / as the delimiter. So: /\\r/. To test that a string contains only \r, \n, or space, you can use /^[\r\n ]+$/ (which requires there be at least one character that matches, and uses ^ to indicate start-of-string, and $ to indicate end-of-string):

    if (demo[i].innerHTML.match(/^[\r\n ]+$/) {
        // Remove it
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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
So I'm trying to write some code to hide a piece of javascript in
Alright... I'm trying to write some javascript code that will apply to an html
I am trying to write some code that allows SVG elements to be dragged
I am trying to write some javascript that will automatically take text in a
I am trying to open a new window and write some elements and javascript
I'm fairly new to JavaScript and am trying to write some code that lists
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

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.