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.
source share