简体   繁体   中英

Why doesn't my String/selector concatenation work?

Can anyone tell me why this doesn't work:

var cfHTML = '<div class="touch-feild" onclick="showPreview('+$(this).find('.feed-thumb')+')"></div>';

I get an "Uncaught SyntaxError: Unexpected identifier"

Hope someone can help me out here. I guess it must be a pretty simple question :-)

Thanks

It think what you want to accomplish is onclick="showPreview($(this).find('.feed-thumb'))" in your .

var cfHTML = '<div class="touch-feild" onclick="showPreview($(this).find(\'.feed-thumb\'))"></div>';

$(this).find('.feed-thumb') will give you jquery object not string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM