|
-
Jan 10th, 2013, 12:20 PM
#1
Thread Starter
Addicted Member
Compare paragraph text
I have paragraph with class copyright. Now, I want javascript to take that value and do compare. For example
If value of paragraph is not equal to Some text then alert something. I looked on google for solution but nothing work. Neither getelementbyid().innerhtml or something else. What now?
-
Jan 11th, 2013, 01:32 PM
#2
Hyperactive Member
Re: Compare paragraph text
what is the text in? Is it inside a div? Or some other object? You can use, as you suggested, get element by ID but it has to be in some element, with a unique id.
EX:
Code:
<html>
<head>
<javascript type="text/javascript">
function checkMe(){
var p1 = document.getElementByID("P1").innerHtml
var p2= document.getElementByID("P2").innerHtml
alert(p1 + " " + p2)
}
</javascript>
</head>
<body>
<div id="p1" >Hello world</div>
<div id="p2" >Hello world</div>
<button onclick="checkMe()"/>
</body>
</html>
This is just freehand, so it might need some tweaking. If this doesnt work, post what you have.
jason
if i was able to help, rate my post!
-
Jan 12th, 2013, 06:57 AM
#3
Thread Starter
Addicted Member
Re: Compare paragraph text
I have something like this:
Code:
<div id="footer">
<p id="copyright">All rights reserved © 2013 Design4U</p>
</div>
Of course, footer div is inside main div. So, how I get text from this paragraph?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|