javascript - Jquery to check height and add class -
I am trying to check which division has a large height and in that space, compared to a class is big.
I have this code
$ (document) .ready (function () {var sideNavMenu = $ ("col-md-3") height () ; Var mainColumn = $ ("col-md-9") height (); if (sideNew menu> main column) {$ ("col-md-3"). AddClass ('dotright');} and {$ ("Col-md-9"). AddClass ('dotLeft');}}); The goal here is whether the side navigation menu is higher than the main column compared to the place on its divi tag.
If the main column is large, then the left tag on its div.
But it is not working.
Any suggestions on how to change / improve.
Thank you very much
You do not refer to these sections based on ID Because, on the page there may be several elements with these class names. should be one with only every ID $ (document) .ready (function () {var sideNavMenu = $ ("# sidebar"). Height (); var main column = $ ("# main") height () ; If (sideNew menu> main column) {$ ("# sidebar"). AddClass ('dotRight');} and {$ ("#.") .addClass ('dotLeft');}}); Of course, you can use the ID in your & lt; Div & gt; respectively. Says:
Get the calculated height of the current for the first element in the set of matched elements or set the height of each matched element.
But, I was just playing with Jsfiddle and it seems that an object has the height of the first element.
This means that you should be able to:
$ (document) .ready (function () {var sideNavMenu = $ ("Col-md-3") height (); var mainColumn = $ ("col-md-9") .height (); if (JSON.stringify (sideNavMenu)> JSON.stringify (main column) ) {$ ("Col-md-3"). AddClass ('dotRight');} and {$ (".- MD-9"). AddClass ('dotLeft');}}); But I like the way I said the first. It is not stable, because more objects can be presented with the same class. The only reason I am also mentioning this is to tell why you had a problem with your original code. :)
Comments
Post a Comment