how to insert <a> in <td>
I am creating <td>
and adding data to it.
$("<td>").addClass("tableCell1").text(mydata).appendTo(trow);
now if I have to create an <a>
tag inside how to do it?
example:
<td headers="xx开发者_如何学JAVA">
<a href="#" title="zz</a>
</td>
EDIT:
$("<td>").addClass("tableCell1").text(mydata).appendTo(trow);
is working fine but
$('a').attr({ href: '#', title: 'title here' }).appendTo($('td')).appendTo(trow);
is not working, I am not getting the <a>
under <td>
I would do something like this:
$("td.tableCell1").append('<a href="#" title="zz"></a>');
EDIT: Or for even more safety in selecting the proper <td>
, you should be able to use
$("td.tableCell1", trow).append('<a href="#" title="zz"></a>');
For even EVEN more safety, you could
$("td.tableCell1:lastChild", trow).append('<a href="#" title="zz"></a>');
I am assuming that you're trying to create the <a>
and the <td>
at the same time. If you're trying to add the <a>
at a different event, you would need a different solution.
$("<td/>",{"class":"tableCell1", text:mydata})
.append($("<a/>",{ href:"#", title:"zz"}))
.appendTo(trow);
Note that you didn't indicate any content for the <a>
in your question. If not styled properly, it will be invisible. If you want to add some text, add text: "some text"
to the <a>
creation.
精彩评论