JQuery: Uncaught TypeError: Cannot read property 'nodeType' from undefined

I am using the jquery UI Position plugin: http://jqueryui.com/position/ to place my icons on a web page. Selectors are captured from the database and output to JS using PHP in the $ myselector variable. This is my current code:

var element_selector='<?php echo $myselector;?>'; $('#inline_docxdiv .Featured.Slider').position({ my: "center", at: "right top", of: $(element_selector) }); //append icons,applicable to all $(divname<?php echo $uniqueid;?>).append('<div id="inline_docxdiv" class="<?php echo $uniqueid;?>"><div id="helpericons_display"><a class="<?php echo $title_toolsetdisplayed;?>" id="questionmarkicon_inlinedoc" title="Display Explanation"><img src="<?php echo $helper_iconpng;?>"></a><a target="_blank" href="<?php echo admin_url().'post.php?post='.$id_toolsetdisplayed.'&action=edit';?>" class="<?php echo $title_toolsetdisplayed;?>" id="sourceicon_inlinedoc" title="View source"><img src="<?php echo $helpersource_iconpng;?>"></a></div></div>'); 

However, the icons are not added correctly and it returns an error in the console:

Uncaught TypeError: Cannot read the 'nodeType' property from undefined

The strange thing is that if I hard code the selector in JS code (not PHP output), everything works fine and the console does not return an error. This is the code in which I hardcoded the element selector:

 var element_selector='.idoc-featured-slider'; 

Is there a way to use PHP to output a selector and not encounter an error? Thanks for any help.

+6
source share
5 answers

I had a similar problem. I got the following error:

Uncaught TypeError: Cannot read the 'nodeType' property from undefined

With these dialog box configuration settings:

 position: {my: "center", at: "left top", of: "window"} 

In jQuery documentation, the value of the "of" property is more an object than a string. Therefore, when I changed the position values ​​to the following:

 position: {my: "center", at: "left top", of: window} 

the error has disappeared.

+13
source

The problem is that of:$() does not work if the object / selector is invalid.

+2
source

Please check your code if any tags are not closed or not. I tried the same thing and it worked correctly. Apparently I had an extra tag

0
source

Usually this error occurs when you do not apply the properties of methods such as prop () Eg: $(#"id").prop() If you did not specify your properties except for this error.

0
source

In my case, I just changed the following in my error message [DataTables warning: table id = bootstrap-data-table2 - The requested unknown parameter '0' for row 0. For more information about this error, see Http: // datatables. net / tn / 4] is gone:

From:

  [enter image description here][1] <tbody> @foreach (var item in Model.HRMS_Tbl_ExpenseClaimModelList) { <tr> @if (item.Approved == "1") { <td>@item.Date</td> <td>@item.Date</td> <td>@item.Type</td> <td>@item.Amount</td> } </tr> } </tbody> TO: <tbody> @foreach (var item in Model.HRMS_Tbl_ExpenseClaimModelList) { if (item.Approved == "1") { <tr> <td>@item.Date</td> <td>@item.Date</td> <td>@item.Type</td> <td>@item.Amount</td> </tr> } } </tbody> 
0
source

All Articles