46170

prettyphoto wont load when writing href using document.write

Question:

i have some codes like this

<span id="$RsC" class="menu" title="Action menu" onclick="menu(\''.$RsC.'\')">click</span> function menu(id){ var d = document.getElementById(id); d.innerHTML ='<a href="somthing;iframe=true&amp;width=400&amp;height=170" rel="prettyPhoto[iframe]" >Doesnt work</a>'; } <script type="text/javascript" charset="utf-8"> jQuery.noConflict(); jQuery(document).ready(function($) { $(".pp_pic_holder").remove(); $(".pp_overlay").remove(); $(".ppt").remove(); $(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'h0mayun'}); }); </script>

the problem is that after clicking on <em>"click"</em> and writing html link prettyPhoto plugin doesn't load

any help will be appreciated.

EDIT------------------- damn you conflict it was again jquery conflict but to got it work i change function to this:

<script type="text/javascript" charset="utf-8"> jQuery.noConflict(); jQuery(document).ready(function($) { $(".pp_pic_holder").remove(); $(".pp_overlay").remove(); $(".ppt").remove(); $(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'h0mayun'}); }); </script> function menu(id){ var d = document.getElementById(id); d.innerHTML ='<a href="somthing;iframe=true&amp;width=400&amp;height=170" rel="prettyPhoto[iframe]" >Doesnt work</a>'; jQuery.noConflict(); jQuery(document).ready(function($) { $(".pp_pic_holder").remove(); $(".pp_overlay").remove(); $(".ppt").remove(); $(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'h0mayun'}); }); }

Answer1:

And it is not going to work this way. You initialize prettyPhoto for existing elements on the page after your page was loaded. When you insert a new element, prettyPhoto plugin knows nothing about it, because it already "attached" itself to the elements existed before. You have to initialize prettyPhoto after all changes on the page or attach it after changes to the updated elements. Like this

function menu(id){ var d = document.getElementById(id); d.innerHTML ='<a href="somthing;iframe=true&amp;width=400&amp;height=170" rel="prettyPhoto[iframe]" >Doesnt work</a>'; $('a', d).prettyPhoto({theme:'h0mayun'}); }

ps: I've made a simple test with the example of prettyPhoto and it is working

function menu(id){ var d = document.getElementById(id); d.innerHTML ='<a href="images/fullscreen/3.jpg" rel="prettyPhoto[gallery1]">Test link</a>'; $('a', d).prettyPhoto(); }

Answer2:

If you're doing this $(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'h0mayun'}); before the onClick function.

You would have to do it again after you have written the html of the object so the plugin would initialize again.

Recommend

  • Using target on div without a href
  • Batching in py2neo
  • How to display the hotel names that have the maximum count from data base by calculating sum in PHP?
  • Why are views not counted if you embed a youtube iframe dynamically using jquery?
  • Two column unique constraint ActiveAndroid
  • Jquery Show & ScrollTop (or ScrollTo)
  • How to add regEx in angular filter
  • cd command not working with execvp
  • Problems with toDataURL HTML5 other ways to get canvas data?
  • Find JSON nested nodes using multiple string values
  • Can't delete or rename original file after resizing
  • D3 get axis values on zoom event
  • Adjust width of select element according to selected option's width
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • Jquery UI tool tip close icon
  • DomPDF {PAGE_NUM} not on first page
  • Javascript simulate pressing enter in input box
  • How to set/get protobuf's extension field in Go?
  • MySQL WHERE-condition in procedure ignored
  • How to show dropdown in excel using jrxml (jasper api)?
  • Importing jscolor library in angular 2
  • Web-crawler for facebook in python
  • Rearranging Cells in UITableView Bug & Saving Changes
  • R: gsub and capture
  • Circular dependency while pushing http interceptor
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • Linker errors when using intrinsic function via function pointer
  • A cron job substitute?
  • trying to dynamically update Highchart column chart but series undefined
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • python draw pie shapes with colour filled
  • Binding checkboxes to object values in AngularJs
  • java string with new operator and a literal
  • How to load view controller without button in storyboard?