Pham Minh Tan
Pham Minh Tan

Reputation: 2096

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 code debug

But it's gerenate to HTML like this:

HTML code

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

Upvotes: 0

Views: 228

Answers (1)

Nika Javakhishvili
Nika Javakhishvili

Reputation: 462

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

Upvotes: 1

Related Questions