javascript - ckeditor insertHtml() form jquery.load -


<script type="text/javascript"> $( "#x_img" ).load( "../x_img.php?id=123" );   $("#x_img").delegate("img", "click",function() {        ckeditor.instances.editor1.inserthtml('<img src="'+$(this).attr('alt')+'" />'); }); </script> 

i have function loads images (x_img) user use. x_img jq.load in page.

using code click image insert, works ok. but, cannot image src value!

ckeditor shows this: <img src="undefined" />

is problem image on page?

if editor showing

<img src="undefined" />

then

$(this).attr('alt') 

will return undefined because img node doesn't have alt='something' attribute. undefined being concated img's src attribute.

try changing image tag following:

<img alt="/images/funtimesatthebeach.jpg" /> 

then, code should load image @ /images/funtimesatthebeach.jpg.


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -