I have a pixel-sized table which cells' width depends on the content. There are input elements in the first row of the table and I need them to have the same width as they parents (). The idea is that those inputs' width should be calculated automatically and set in pixels with jQuery. There are no classes nor id's for those cells and inputs. I'm able to set the width for one cell only using selectors with code like this:
var parentWidth = $(".foo").width();
$('td.foo input').width(parentWidth);
But as I said I need it to be more universal without using any classes etc. Can anyone help me with that? Thank you!
jQuery width() Method The width() method sets or returns the width of the selected elements. When this method is used to return width, it returns the width of the FIRST matched element. When this method is used to set width, it sets the width of ALL matched elements.
Use jquery Width command with the jcrop boxWidth, create a div layer around the image and then find the width using the command! boxWidth: $("#cropwindow"). width(), this will give you the width of the responsive area!
jQuery width() and height() MethodsThe width() method sets or returns the width of an element (excludes padding, border and margin). The height() method sets or returns the height of an element (excludes padding, border and margin).
The jQuery width() method uses to set and get the width of an element. So when we call width() method on selector(can be element name, id or class) without any parameter or without passing any value, then it returns the width of that particular element.
You could use a child selector like this
$('tr:first td > input').each(function(){
$(this).width($(this).parent().width());
});
This code should select all td of the first row and give them the width of their parent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With