Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Need to get InnerHTML Javascript

    Javascript example!

    I need to get Document InnerHTML on my webpage into a string



    My Guess? below
    Var Message= INNERHMTL ?? then split it with "/"



    here's what's on my webpage

    First Name/last Name

    Ben/Porter
    Mat/Cyber
    Dave/Norton

    split first and last name with "/" sign

    thank for any help

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Code:
    <script type="text/javascript">
    window.onload=function(){
    var el=document.getElementById('content');
    var remBr=el.innerHTML.split(/<br>/); // Split when br tag is found
    for(var i=0;i<remBr.length;i++)
    	{
    	remBr[i]=remBr[i].replace(/\s/g,''); // Remove trailing spaes
    	var fLname=remBr[i].split(/\//); // Split when "/" is found
    	alert('First Name: '+fLname[0]+'\nLast Name: '+fLname[1]);
    	}
    }
    </script>
    <p id="content">
    Ben/Porter<br>
    Mat/Cyber<br>
    Dave/Norton
    </p>
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New Coder
    Join Date
    May 2008
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Great example

    rangana
    Thanks Thats worked for me


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •