Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  164] [ 4]  / answers: 1 / hits: 44268  / 11 Years ago, tue, may 14, 2013, 12:00:00

Let's say the String Done successfuly is displayed somewhere in a webpage , is there a way to know if this string exist using javascript only ?
Thanks.


More From » javascript

 Answers
315

More details would help. There may be better ways. But this is the best given what information you've provided:



if (
(
document.documentElement.textContent || document.documentElement.innerText
).indexOf('Done successfuly') > -1
) {
// Do something...
}


If you know the ID or class-name or can otherwise select the element that directly contains the text (e.g. h1#someHeading span ...) then you should probably do that as it will be more performant and generally a cleaner approach.



EDIT Worth noting: This approach will pick up text within SCRIPT and STYLE tags too, which is probably not what you want. Both textContent and innerText have various quirks across browsers too. See this for more info.


[#78235] Monday, May 13, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kyla

Total Points: 77
Total Questions: 108
Total Answers: 111

Location: Grenada
Member since Mon, May 8, 2023
1 Year ago
;