Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Compare innerText to a string constant

Posted on 2014-10-30
5
109 Views
Last Modified: 2014-11-18
How do I compare innerText to a string constant?  

var REQUIRED = "** Required **"

var theclass = document.getElementById("<%= FK_classification.ClientID %>");
alert(theclass.innerText);

I want to in effect do: Is  theclass.innerText equal to "** Required **"
0
Comment
Question by:HLRosenberger
  • 3
  • 2
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40414245
var theclass = document.getElementById("<%= FK_classification.ClientID %>");
theText  = theclass.textContent = theclass.innerText

if(theText!=REQUIRED){
  //different
}

Open in new window

0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 40414271
theText  = theclass.textContent = theclass.innerText

What does this statement do?  double assignment?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40414277
It's for cross browser support

Actually on double checking innerText seems supported by Firefox now but best to keep it for older browsers.
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40414291
And I screwed up there it should be
theText  = theclass.innerText || theclass.textContent 

Open in new window

0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 40450246
thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question