jquery src returning "Undefined" in Wordpress

Asked

Viewed 58 times

0

I have a function to create extra fields in the profile editor of users of a site in Wordpress. A part of it creates two image upload fields (media Uploader with thickbox), and a snippet in jQuery to fill in a text input with the image URL, and a placeholder (img) with the image itself. That’s basically the result:

inserir a descrição da imagem aqui

The media Uploader must provide the url with:

var imgurl = $( 'img', html ).attr( 'src' );

It’s working normally on localhost, but when I put it on the server, it doesn’t work. The log shows "Undefined", and interestingly only in Chrome (but works in Chrome on localhost).

Any ideas? If relevant, I can post the entire code.

  • if you change the var imgurl to a fixed value it works?

  • Yes, it works normal. So I guess there’s only one problem left with the $( 'img', html ).attr( 'src' ); (I just don’t know which...)

  • I think the problem is using $... check out: http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers

1 answer

0

I discovered by researching the OS in English (here). Instead of using:

imgurl = $( 'img', html ).attr( 'src' );

...just use

imgurl = $( html ).attr( 'src' );

Strange is that the first way works on localhost... Thanks to those who tried to help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.