Solved

Compare innerText to a string constant

Posted on 2014-10-30
5
120 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
[X]
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
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

623 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