Reputation: 157
<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 a function that loads images (x_img) for user use. x_img jq.load in this page.
Using this code I click the image to insert, which works OK. But, I cannot get the image src
value!
CKEditor shows this: <img src="undefined" />
Is the problem that the image is on another page?
Upvotes: 0
Views: 325
Reputation: 617
If your editor is showing
<img src="undefined" />
then
$(this).attr('alt')
will return undefined
because the img
node doesn't have an alt='something'
attribute. This undefined
is then being concated into your img
's src
attribute.
Try changing your image tag to something like the following:
<img alt="/images/funtimesatthebeach.jpg" />
Then, your code should load the image at /images/funtimesatthebeach.jpg
.
Upvotes: 1