简体   繁体   中英

Get width from other element to set to current element but not equals in jQuery

I have a input. I want my div when I append it, it has same width of input. Here my code.

$("#search-result").width($("#searchForm").width());

But $("#search-result")'width not equals $("#searchForm")'s width. I try to debug it in Chrome inspect element.

jQuery代码调试

But it's gerenate to HTML like this:

HTML代码

Why? Is there any solution to make same width? Thanks

var searchWidth = $("#searchForm").width() + 'px';
$("#search-result").css('width', searchWidth );

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