Skip to main content

Posts

Showing posts with the label removeclass

jQuery removeClass only working with actual class name, not var

I created a page to play around with the 960 Grid System, learn about div placement. There are up to four divs on the page. When a new grid size, pull or push value is selected from a dropdown, I need to remove the current class, i.e. grid_8 , pull_5 or push_4 , and add the newly selected class. function alter_grid1(new_class_name){ var old = document.getElementById('grid1'); var classes = old.className.split(' '); var old_class_name = 'cessna'; $.each(classes, function(){ if(old_class_name == 'cessna' || old_class_name == null){ old_class_name = this.match('/grid_1|grid_2|grid_3|grid_4|grid_5|grid_6|grid_7|grid_8|grid_9|grid_10|grid_11|grid_12|grid_13|grid_14|grid_15|grid_16|grid_17/'); } }); $(old).removeClass('grid_1 grid_2 grid_3 grid_4 grid_5 grid_6 grid_7 grid_8 grid_9 grid_10 grid_11 grid_12 grid_13 grid_14 grid_15 grid_16').addClass(new_class_name); console.log('Old grid1 clas

jQuery removeClass only working with actual class name, not var

I created a page to play around with the 960 Grid System, learn about div placement. There are up to four divs on the page. When a new grid size, pull or push value is selected from a dropdown, I need to remove the current class, i.e. grid_8 , pull_5 or push_4 , and add the newly selected class. function alter_grid1(new_class_name){ var old = document.getElementById('grid1'); var classes = old.className.split(' '); var old_class_name = 'cessna'; $.each(classes, function(){ if(old_class_name == 'cessna' || old_class_name == null){ old_class_name = this.match('/grid_1|grid_2|grid_3|grid_4|grid_5|grid_6|grid_7|grid_8|grid_9|grid_10|grid_11|grid_12|grid_13|grid_14|grid_15|grid_16|grid_17/'); } }); $(old).removeClass('grid_1 grid_2 grid_3 grid_4 grid_5 grid_6 grid_7 grid_8 grid_9 grid_10 grid_11 grid_12 grid_13 grid_14 grid_15 grid_16').addClass(new_class_name); console.log('Old grid1 clas