January 7, 2011

How to add duplicate image on same page with java Script after page loaded

Question by Shoun

i m facing a problem, what i ma doing is that. i have a server side image button. what i wana do is that after that page loads at client side, i want to place that same image with same navigation url at another location on same page. Can any body tell me how to do that? same as i also want to hide some text on page with javascript. any idea??

Answer by Starx

use .clone() method.

An Example:

Let ‘s suppose your img being this

<img class="yourimageclass" src="Your/path/to/image.jpg" ?>
<!-- And this being where you want to copy it -->
<div class="whereuwanttocopy"></div>

Then your jQuery would be


To hide some text in your page, wrap them into some container, so that we could address that piece of content

<span class="todhide">here is the text to hide</span> and here is the text to not hide

Then use simple $(".tohide").hide() whenever you want to hide the text

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!