treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Using JavaScript in Wordpress

  • Hi everybody

    I´m tryng to apply some JavaScript to modify the width of three css classes. This is the code of my index.php, but nothing happens. I´m really new at using jquery and Javascript, perhaps this isn´t allowed?

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <div id="blog">
    
      <div id="destacados">
      <script type="text/javascript">
       $(function() {
      $('.destA').hover(function() {
          $('.destB,.destC').css('width', '40');
      }, function() {
          $('.destB,.destC').css('width', '');
      }
    
      );
      $('.destB').hover(function() {
          $('.destA,.destC').css('width', '40');
      }, function() {
          $('.destA,.destC').css('width', '');
      }
    
      );
      $('.destC').hover(function() {
          $('.destA,.destB').css('width', '40');
      }, function() {
          $('.destA,.destB').css('width', '');
      }
    
      );
    

    });

        </div>
    
        <div class="destB">
    
        </div>
    
    
        <div class="destC">
    
        </div>
    
    
    
      </div>
    

  • I'm no jquery pro by any means, but I can tell you that the $ to call variables conflicts with WordPress's variables..

    try wrapping your jquery in:

    jQuery(function ($) {
      /* You can safely use $ in this code block to reference jQuery */
    });
    
  • It totally worked.

    Thanks man.