Enjoy an ad free experience by logging in. Not a member yet?
Register .
05-03-2012, 05:19 PM
PM User |
#1
Banned
Join Date: Mar 2007
Posts: 1,523
Thanks: 116
Thanked 0 Times in 0 Posts
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
05-03-2012, 05:24 PM
PM User |
#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
05-03-2012, 07:36 PM
PM User |
#3
The fat guy next door
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 Posts
$('#photos li a').attr('rel', 'lightbox[set]');
__________________
Don’t click this link !
05-04-2012, 02:38 PM
PM User |
#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>
05-04-2012, 03:06 PM
PM User |
#5
The fat guy next door
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 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.
__________________
Don’t click this link !
05-04-2012, 03:41 PM
PM User |
#6
Banned
Join Date: Mar 2007
Posts: 1,523
Thanks: 116
Thanked 0 Times in 0 Posts
05-04-2012, 04:04 PM
PM User |
#7
The fat guy next door
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 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.
__________________
Don’t click this link !
05-06-2012, 10:13 AM
PM User |
#9
The fat guy next door
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 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.
__________________
Don’t click this link !
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 12:15 AM .
Advertisement
Log in to turn off these ads.