I use jQUery UI Position plugin: http://jqueryui.com/position/ to position my icons on a web page. The selectors are grabbed from the database and outputted to JS using PHP in a $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 appended correctly and it returns an error in the console:
Uncaught TypeError: Cannot read property 'nodeType' of undefined
The strange thing is that if I hard-code the selector in the JS code (not outputted by PHP), everything works OK and no error returned in the console. This is the code where I hard-coded the element selector:
var element_selector='.idoc-featured-slider';
Is there a way to use PHP to output the selector and not encountering the error? Thanks for any help.
I ran into a similar issue. I was getting the following error:
Uncaught TypeError: Cannot read property 'nodeType' of undefined
With these dialog position configuration values:
position: {my: "center", at: "left top", of: "window"}
Per the jQuery UI documentation, the value of the "of" property is an object rather than a string. So, when I changed the position values to the following:
position: {my: "center", at: "left top", of: window}
the error disappeared.
The problem is due to the of:$()
not working if the object/selector is not valid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With