Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question JQuery to add an attribute

    hi, I need to add an attribute to #photos li a

    the attribute is rel="lightbox[set]"

    can anyone please help?

    thanks

  • #2
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    I have tried something like this:
    Code:
    <script>
    var title = $("rel").attr("lightbox[set]");
      $("#photos li a").text(title);
    </script>
    doesn't work

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,680
    Thanks
    6
    Thanked 1,009 Times in 982 Posts
    $('#photos li a').attr('rel', 'lightbox[set]');

  • #4
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    thanks but this still doesn't work?!
    Code:
    <script>
    $('#photos li a').attr('rel', 'lightbox[set]');
    </script>
    	<div id="photos">
    		<?php foreach ( $photos as $photo ) echo '<li>'.wp_get_attachment_link( $photo->ID ).'</li>' ?>
    	</div>

  • #5
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,680
    Thanks
    6
    Thanked 1,009 Times in 982 Posts
    It does work for me. Open Firebug or a similar debugging tool and view the HTML. How does it look? Also, watch out for any JavaScript errors; you can check those in the console.

  • #6
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

  • #7
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,680
    Thanks
    6
    Thanked 1,009 Times in 982 Posts
    Yeah, if you’re using the error console you will see the message “$ is not defined”. This is because you have called your function before jQuery itself is even included in the page. The reference to the jQuery core library must always come first, then your own jQuery functions.

  • #8
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question

    I have just tried this on another site and it's not working?!

    http://www.jbiddulph.com/index.php/gallery

  • #9
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,680
    Thanks
    6
    Thanked 1,009 Times in 982 Posts
    Don’t know if it’s related to that but your HTML is wrong. The div with the ID “photos” must be a ul. List items cannot be direct children of a division. And the script element must have a type attribute with value text/javascript. And you have more unrelated HTML errors.


  •  

    Tags for this Thread

    Posting Permissions

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