SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jan 2009
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wordpress jquery

    Wordpress jquery

    Hi all

    I have a super simple WP site here as a demo

    http://www.ttmt.org.uk/forum/wordpress

    It's a header.php, footer.php, index.php and page.php.

    I have one page called Page that uses page.php as it's template. The header list the pages so has 'Page' in the header.

    Page.php simple has <h4 id="oneBtn">Red</h4>

    In header.php I have this jquery to change the color of #oneBtn when the button in the header in clicked.


    Code:
    <script type="text/javascript">
        
        $(document).ready(function(){
        	$('#nav li a').click(function(){
    		$('#oneBtn').css('color','red');
    	});
        });  
    
      </script>
    This doesn't work and I can't see why.

    Once the page has loaded and the Page button in the header is clicked again

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ttmt View Post
    This doesn't work and I can't see why.
    Where is the #nav element?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict
    Join Date
    Jan 2009
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the #nav element is in the header.php

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ttmt View Post
    the #nav element is in the header.php
    It seems with your wordpress page that you'll need to use jQuery instead of $
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Addict
    Join Date
    Jan 2009
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm using jQuery now but still having the same problem

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ttmt View Post
    I'm using jQuery now but still having the same problem
    It's symptoms that look the same (it doesn't work) but that are now caused by a different problem.
    Step by step, fixing one thing at a time. That's how such things are resolved.

    The HTML tags for your script tag doesn't seem to be complete now.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •