How to assign classes to all elements?

Is it possible to assign classes to elements of certain type?
For example, all paragraphs in the post body or comment body should have class=”paragraph”, all unordered lists in post body should have class=”list”, and so on.

Related posts

1 comment

  1. Jquery solution:

    **assuming your posts are in a division with the class of “post”.

    <script type="text/javascript">
        $(document).ready(function(){ 
          $(".post p").each(function(){ 
          $(this).addClass('paragraph'); 
           });
          $(".post ul").each(function(){ 
          $(this).addClass('list'); 
           });
          //add more lines here to select more elements
        });
    </script>
    

    Paste this in your footer.

    *you need jquery installed. And better yet would be to enque this using http://codex.wordpress.org/Function_Reference/wp_enqueue_script

Comments are closed.