Results 1 to 3 of 3

Thread: Compare paragraph text

  1. #1

    Thread Starter
    Addicted Member Mr.Joker's Avatar
    Join Date
    Apr 2012
    Posts
    140

    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?

  2. #2
    Hyperactive Member jasonwucinski's Avatar
    Join Date
    Mar 2010
    Location
    Pittsburgh
    Posts
    452

    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!

  3. #3

    Thread Starter
    Addicted Member Mr.Joker's Avatar
    Join Date
    Apr 2012
    Posts
    140

    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
  •  



Click Here to Expand Forum to Full Width