jquery src returning "undefined" in WordPress

0

I have a function to create extra fields in the profile editor of a site's users in WordPress. A part of it creates two image upload fields (media uploader with thickbox), and a jQuery snippet to populate a text input with the URL of the image, and a placeholder (img) with the image itself. This is basically the result:

Themediauploadershouldprovidetheurlwith:

  

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

It'sworkingnormallyonlocalhost,butwhenIputitontheserver,itdoesnotwork.Thelogshows"undefined", and interestingly only in Chrome (but works in Chrome on localhost).

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

    
asked by anonymous 19.02.2015 / 00:28

1 answer

0

I discovered searching 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 it works in localhost ... Thanks to anyone who tried to help.

    
19.02.2015 / 03:28