How to detect if id exists on window.opener screen

How to detect if id exists on window.opener screen

Hello,

Im trying to detect if an id exists on a window.opener to keep from creating a duplicate. But Im getting an error.

var $id = this.value;                                                 
if(window.opener.$("#" + $id).length == 0) {                          
window.opener.$("#CC").append('<br><input type="text" name="SCCC" ...id="MYID"

Im getting the below error.

 
  1. Uncaught Error: Syntax error, unrecognized expression: #MYID