如何申请;id";在Jquery的以下代码中

如何申请;id";在Jquery的以下代码中,jquery,Jquery,在类为“parent”的元素下动态创建元素 并对其应用了一些css类,即“child” 现在我想对它应用一些“id”,所以我想知道如何做 $(".parent").append("<a class='child' href='#bookmark" + cAnchorCount++ + "'> "+ $(this).text() +"</a>"); $(“.parent”)。追加(“”); 以及如何将一些事件绑定到它,比如鼠标悬停事件 我试过了,但没有成功 $(".p

在类为“parent”的元素下动态创建元素 并对其应用了一些css类,即“child” 现在我想对它应用一些“id”,所以我想知道如何做

$(".parent").append("<a class='child' href='#bookmark" + cAnchorCount++ + "'> "+ $(this).text()  +"</a>");
$(“.parent”)。追加(“”);
以及如何将一些事件绑定到它,比如鼠标悬停事件

我试过了,但没有成功

$(".pushLinkBtnContainer").append("<a id='$(this).text()' class='pushLinkBtn' href='#bookmark" + cAnchorCount++ + "'>".bind("mouseover", function() {
                $(this).css("background-color", "red");
            }) + "</a>");
$(.pushLinkBtnContainer”).append(“”);
简单id:

$(".pushLinkBtnContainer").append("<a id='someid' class='pushLinkBtn' href='#bookmark" + cAnchorCount++ + "'> "+ $(this).text()  +"</a>");
$(.pushLinkBtnContainer”).append(“”);
使用:

$(.pushLinkBtnContainer”).append(“”);

不清楚您想做什么。为什么需要id?您是否正在尝试向锚元素添加id好的,让我编辑我的问题,以及如何对其应用一些事件,如鼠标悬停事件?答案非常清楚!)我如何将一些事件应用于它,比如鼠标悬停事件?@Faizan如下:
$(.pushLinkBtnContainer”).on(“mouseover”,“someid”,function(){//execute statements})我不能在同一个函数中的同一行中添加事件吗?@Faizan像这样<代码>$(“.pushLinkBtnContainer”)。附加(“”)
$(".pushLinkBtnContainer").append("<a id='someid"+variable_name+"' class='pushLinkBtn' href='#bookmark" + cAnchorCount++ + "'> "+ $(this).text()  +"</a>");
$(".pushLinkBtnContainer").append("<a id='"+variable_name+"' class='pushLinkBtn' href='#bookmark" + cAnchorCount++ + "'> "+ $(this).text()  +"</a>");
$(".pushLinkBtnContainer").on("mouseover","#someid",function(){
    //execute statements
});
$(".pushLinkBtnContainer").append("<a id="'pushLinkBtn_' + cAnchorCount + '" class='pushLinkBtn' href='#bookmark" + cAnchorCount++ + "'> "+ $(this).text()  +"</a>");
$(".pushLinkBtnContainer").append("<a id='" + cAnchorCount + '" class='pushLinkBtn' href='#bookmark" + cAnchorCount++ + "'> "+ $(this).text()  +"</a>");