Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-03-2012, 05:19 PM   PM User | #1
jarv
Banned

 
Join Date: Mar 2007
Posts: 1,523
Thanks: 116
Thanked 0 Times in 0 Posts
jarv can only hope to improve
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
jarv is offline   Reply With Quote
Old 05-03-2012, 05:24 PM   PM User | #2
jarv
Banned

 
Join Date: Mar 2007
Posts: 1,523
Thanks: 116
Thanked 0 Times in 0 Posts
jarv can only hope to improve
I have tried something like this:
Code:
<script>
var title = $("rel").attr("lightbox[set]");
  $("#photos li a").text(title);
</script>
doesn't work
jarv is offline   Reply With Quote
Old 05-03-2012, 07:36 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
$('#photos li a').attr('rel', 'lightbox[set]');
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 05-04-2012, 02:38 PM   PM User | #4
jarv
Banned

 
Join Date: Mar 2007
Posts: 1,523
Thanks: 116
Thanked 0 Times in 0 Posts
jarv can only hope to improve
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>
jarv is offline   Reply With Quote
Old 05-04-2012, 03:06 PM   PM User | #5
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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!
VIPStephan is offline   Reply With Quote
Old 05-04-2012, 03:41 PM   PM User | #6
jarv
Banned

 
Join Date: Mar 2007
Posts: 1,523
Thanks: 116
Thanked 0 Times in 0 Posts
jarv can only hope to improve
Is thsi still working? http://cyclerevival.jupitercolour.net/bikes/bmx/
jarv is offline   Reply With Quote
Old 05-04-2012, 04:04 PM   PM User | #7
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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!
VIPStephan is offline   Reply With Quote
Old 05-06-2012, 01:41 AM   PM User | #8
jarv
Banned

 
Join Date: Mar 2007
Posts: 1,523
Thanks: 116
Thanked 0 Times in 0 Posts
jarv can only hope to improve
Question

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

http://www.jbiddulph.com/index.php/gallery
jarv is offline   Reply With Quote
Old 05-06-2012, 10:13 AM   PM User | #9
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Tags
add, attribute, jquery

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:15 AM.


Advertisement
Log in to turn off these ads.