2014-11-20 67 views
-1

I have a <div id="myPost>" that is populated with the Jquery clone code $(this).clone().appendTo('#myPost');.

I want the users to click in this div, so it will take them to another page. How can you do nest an a href tag in the clone?

The blue area is the cloned part that should be clickable and take you to another page. The blue area has a div called #myPost. So I want to add a link to the following page: #individualProfile. I dont want to add more code because div #myPost gets data from the server via ajax. But I guess my question is how to add an anchor tag inside #myPost when it cloned.

+0

将一个子元素追加到克隆 – meskobalazs 2014-11-20 16:58:35

+1

您可以给我们一个关于最终结果的HTML表示吗?你能告诉我们你试过了什么吗? – PeterKA 2014-11-20 16:59:49

+0

@PeterKA,我知道它似乎很少代码,但我想我所看到的并不需要很多代码。我从另一个名为'#myListView'的div中克隆了#myPost。然后,当被克隆时,我想让用户点击div##myPost(被克隆的),将它们链接到另一个页面。 – user3356128 2014-11-20 17:31:23

回答

1
+0

嗨@贾米巴克,谢谢,但正如你所看到的,我有一个#myList克隆,所以我要追加?这是行不通的:'.appendTo('#myPost'+'')' – user3356128 2014-11-20 17:26:53

+0

你可以在一个单独的调用中完成。查看更新的小提琴:http://jsfiddle.net/ep5k7h74/4/ – 2014-11-20 17:36:01

0

不知道你的HTML使得这个棘手的,但这应该让你开始。

var clonedDiv = $(this).clone(); 
clonedDiv.append('<a href="yourUrl">Link Title</a>'); 
$(this).appendTo('#myPost');