I'm using a jQuery slideToggle to show a hidden table row but it sets the display style to block and I need to to display table-row. any ideas how i could accomplish this?
thanks in advance
I'm using a jQuery slideToggle to show a hidden table row but it sets the display style to block and I need to to display table-row. any ideas how i could accomplish this?
thanks in advance
I figured out a solution to this problem - check if the display has been set to block (if the element has been toggled to be shown) and if so set to desired display type.
$('a.btn').on('click', function() {
$('div.myDiv').slideToggle(200, function() {
if ($(this).css('display') == 'block') $(this).css('display', 'table-row'); // enter desired display type
});
});
slidetoggle()
shows AND hides, but with your modification, it can't hide. –
Howse inorganik's solution is almost working. But you also need to set the step
callback to change block
to table-row
.
$('row-selector-here').slideToggle({
duration: 'fast',
step: function() {
if ($(this).css('display') == 'block') {
$(this).css('display', 'table-row');
}
},
complete: function() {
if ($(this).css('display') == 'block') {
$(this).css('display', 'table-row');
}
}
});
flex
rather than table-row
. I also had to add another if clause to detect when it sets it to none
, and sets it to ''
so external css could apply without being overridden (jquery messes with the element's css directly in the html, which overrides css anywhere, unless !important
is used, which I didn't want to use). –
Ernestineernesto You can use the callback to change this
$('#tableRowId').slideToggle( function(){
$(this).css('display', 'table-row');
});
slideToggle()
shows and hides, this makes it so it can't hide. Check my answer below –
Howse This is a known bug (also here). with jQuery slideToggle
. There isn't any way to use slideToggle
and have it properly preserve the display style. You can apply the display style with a callback when the animation completes, but that may not achieve the effect you desire.
just add this code to callback function
$(this).css('display','');
© 2022 - 2024 — McMap. All rights reserved.