Reputation: 8387
I am generating the iframe
and its id
dynamically.
Now I have a situation to find if the Id
is already existing or not.
My code will be,
function createIframe(intxnId){
alert("Id is : "+"$('#"+intxnId+"')");
if($("'#ch"+intxnId+"'").length == 0){
alert("Creating the new Iframe intxnId is: " +intxnId);
var iframe = "<iframe id='ch"+intxnId+"' src='" + contexPath + "/HeartChat.html?intxnId="+intxnId+"' class='iframeSize'></iframe>";
alert("iFrame Details : "+iframe);
$("#chatMessageArea").find("#messageArea").html(iframe);
}else{
alert("ID is already present !");
}
}
My alert for the dynamic Id is ,
But I got the error as,
Good answers are definitely appreciated !
Upvotes: 2
Views: 148
Reputation: 64526
Your jQuery selector is invalid, for some reason it is wrapped in single quotes. Change to:
if($("#ch"+intxnId).length == 0){
Currently your selector evaluates to:
$("'#chXYZ'") // wrong, it should evaluate to $("#chXYZ")
Also, there is no code in your question that could produce the alert shown.
Upvotes: 1