Solved

Compare innerText to a string constant

Posted on 2014-10-30
5
114 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

739 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