Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Reply To: [Resolved] how to add property of "disabled" or "optgroup" on SELECT menu

$
0
0

I was looking to do the same thing, so i thought I share what worked for me. Place in footer:

<?php 
//You only need this if you want this to run on a specific page.  If you want it on every page, then remove the if statement
if (is_page('my-page-slug')){ ?>
  
   <script>
    jQuery('.my-class select option')
    .each(function() {
        
       var optionText = jQuery(this).html();
        
       //if there are 2 spaces (&nbsp;), then it is our option.  change the variable depending on your needs. 
       //otherwise replace option tag with optgroup
       var m = optionText.match(/(&nbsp;){2}(.*)/g);
        
       if (!m)
           jQuery(this).replaceWith('<optgroup label="'+optionText+'"></optgroup>');     
    });

    </script>
<?php 
}

?>

Viewing all articles
Browse latest Browse all 20145

Trending Articles