Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have created a simple HTML page,
HTML
<body>
	<p>www.google.com</p>
 
	<p>Page contents is here http://somelink.com</p>
</body>


After running this page www.google.com and http://somelink.com appears as a simple text on form.

I need to convert them in hyperlink at runtime....as
www.google.com and
http://somelink.com

Please guide me for this..

any help would be grateful..

Thanks in advance
Posted
Updated 12-Feb-12 23:34pm
v3

use this script

XML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {

        $("p").each(function() {

            this.innerHTML = "<code><a href=http://" + this.innerHTML + ">" + this.innerHTML + "</a></code>";
            alert("ok");
        })

    });
</script>
 
Share this answer
 
Comments
CRDave1988 13-Feb-12 6:00am    
tell me if u face any problem
Vivek Deshmukh 16-Feb-12 2:16am    
Hi,

thanks for ur time..
Actually this solution is able to replace link only within <p> tag. so
I have implemented it by using Regular expression.
hello

you can do as below,

include jQuery javascript file

JavaScript
<script src="jquery.js" type="text/javascript"></script>


your html code should be as below

HTML
<p></p><p class="findLink">www.google.com</p>
 
	<p>Page contents is here </p><p class="findLink">http://somelink.com</p>


and your replace javascript code should be as below

JavaScript
function UpdateLink()
    {
        $(".findLink").each(function(i,e){
            debugger;
            $(e).prev().append("<a href="\""">" + $(e).html() + "</a>");
            $(e).html('');
        });
    }
    UpdateLink();
 
Share this answer
 
Comments
Vivek Deshmukh 16-Feb-12 2:17am    
Hi,

thanks for ur time..
Actually this solution is able to replace link only within findLink class. so
I have implemented it by using Regular expression.
Use HTML Hyperlinks, http://www.w3schools.com/html/html_links.asp[^]

Hope it helps.

I would suggest you to go through the basic HTML Tutorial[^] to start learning HTML.
 
Share this answer
 
v2
Comments
Vivek Deshmukh 13-Feb-12 5:16am    
sir,
I know HTML but i want to change this word to hyperlink at runtime.

do u have any idea fr this ?
Rajeev Jayaram 13-Feb-12 6:08am    
What do you exactly mean my runtime?
XML
<body>
    <p>www.google.com</p>

    <p>Page contents is here <a href="http://somelink.com"> http://somelink.com</a></p>
</body>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900