我有這個功能使用jQuery的元素ID作爲函數的參數作爲選擇
function doSomething(elementID) {
$("div").append("<p id='"+ elementID +"'> A paragraph</p>");
/* this part is incorrect since it will
use the selector whose id is "elementID" and not the parameter passed. */
$("p#elementID").css("color", "red");
}
我想要做這樣的事情,但是這顯然是不正確。如何使用或存儲使用ID參數的選擇器?
像這樣的東西(但這是不正確太):
var x = $("# '"+elementID+");