Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Return matches of both the URL and the Link Text

  1. #11
    Join Date
    May 2015
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks I am now looking at the code and trying to understand it

  2. #12
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I was just giving you examples. None of that in particular is meant to do anything. Except of course the div. That you can paste a link like you were talking about into, and then access it like from a textarea you would use its .value property, for the div, you need its .innerHTML property.

    Perhaps this would have been a better demo:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    #input {
    	width: 500px;
    	height: 400px;
    	border: 1px solid black;
    }
    </style>
    </head>
    <body>
    <div id="input" contenteditable></div>
    <input type="button" value="Get Content" onclick="alert(document.getElementById('input').innerHTML);">
    </body>
    </html>
    Last edited by jscheuer1; 06-08-2016 at 09:35 PM. Reason: add simplified/enhanced demo
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #13
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Perhaps even better:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    #input {
    	width: 500px;
    	height: 400px;
    	border: 1px solid black;
    }
    </style>
    <script type="text/javascript">
    function linkinfo(){
    	var response = '', links = document.getElementById('input').getElementsByTagName('a'), linknum = links.length, alink = -1, thelink;
    	if(linknum){
    		while((thelink = links[++alink])){
    			response += 'Link #' + (alink + 1) + ':\n\xa0\xa0\xa0\xa0\xa0href: ' + thelink.href + '\n\xa0\xa0\xa0\xa0\xa0html: ' + thelink.innerHTML + '\n';
    		}
    	} else {
    		response = "No links currently in the input div."
    	}
    	alert(response);
    }
    </script>
    </head>
    <body>
    <div id="input" contenteditable></div>
    <input type="button" value="Get Content" onclick="alert(document.getElementById('input').innerHTML);"><br>
    <input type="button" value="Get Link Info" onclick="linkinfo();">
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Replies: 3
    Last Post: 12-18-2012, 06:56 AM
  2. Text / Link Help
    By ritchie2100 in forum HTML
    Replies: 3
    Last Post: 04-13-2010, 09:16 PM
  3. Replies: 11
    Last Post: 09-23-2009, 09:49 AM
  4. Comparing Two Arrays, printing matches
    By thesprucegoose in forum JavaScript
    Replies: 2
    Last Post: 04-01-2009, 02:32 PM
  5. Replies: 1
    Last Post: 02-16-2009, 04:40 AM

Bookmarks

Posting Permissions

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