Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: show() keeps adding display:block

Tags:

jquery

I'm having a little issue right now that has turned into a festering wound.

I've recreated Google Business Hours for setting which hours during the week that a company is open, or whether they are closed on that day. Now, if they are closed, the user can select a checkbox and the times DIV hides. Right now I'm using .show() and .hide()

Now, let's say that a user closes the first day and decides to "apply all" to the rest of the days of the week. I loop through and close the remaining 6 days. However, if a user has modified a day in the middle of the week, the .show() or .hide() functions automatically add "display: block" and this messes up the loop.

Why is jQuery adding this styling when it was never there originally, and is there a clean way of removing it within a loop before I apply the .show() or .hide()?

like image 255
dcolumbus Avatar asked Oct 21 '10 15:10

dcolumbus


1 Answers

On an element that you haven't defined the display, after unhidding it, JQUERY will add display block to the element.

You can remove it afterwards.

$("#myrow").show().removeAttr( 'style' )

This includes all dynamic styling so please watch out if you depend on this.

like image 175
Jimmy Kane Avatar answered Oct 23 '22 08:10

Jimmy Kane