473,394 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Adding Attribute to HTML Tag <a href=

Ok here is my question i hope its something easy. I have CMS that generates images from whatever url I put with its corresponding syntax. Well I want to add a Lightbox to does images but instead of going into the CMS to find how where it outputs the actual code that appears i was thinking of using JS to add an attribute of rel="lightbox" to links within a certain div that have a class of media.

Example:
Here is a link to an image that might be found on my page

[HTML]<a href="images/blah.jpg" target="_self" class="media"><img src="images/blah.jpg" /></a>[/HTML]

One way I was thinking of doing it was the function "replace". something like this

Expand|Select|Wrap|Line Numbers
  1. javascript:document.body.innerHTML.replace("Index","67890");
and then this code to find the class which im not sure if it will work.

Expand|Select|Wrap|Line Numbers
  1. //Create an array 
  2. var allPageTags = new Array(); 
  3.  
  4. function doSomethingWithClasses(theClass) {
  5. //Populate the array with all the page tags
  6. var allPageTags=document.getElementsByTagName("*");
  7. //Cycle through the tags using a for loop
  8. for (i=0; i<allPageTags.length; i++) {
  9. //Pick out the tags with our class name
  10. if (allPageTags[i].className==theClass) {
  11. //Manipulate this in whatever way you want
  12. allPageTags[i].style.display='none';
  13. }
  14. }
Can someone please help me put this together. My final link should output as.
[HTML]<a href="images/blah.jpg" target="_self" class="media" rel="lightbox"><img src="images/blah.jpg" /></a>[/HTML]
Jan 10 '08 #1
4 6048
Looking over the Javascript code for getElementByClass it seems like i might not even need the replace function if the getElementByClass code work by replacing the "style.display="none"" to something else right? how do i set a rel?

Please note that im a total Noob at Javascript im more of a php guy.
Jan 10 '08 #2
acoder
16,027 Expert Mod 8TB
Try:
Expand|Select|Wrap|Line Numbers
  1. allPageTags[i].setAttribute("rel","lightbox");
Jan 10 '08 #3
thanx! worked perfectly.
Jan 11 '08 #4
acoder
16,027 Expert Mod 8TB
You're welcome. Glad it worked.
Jan 11 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Charles Nadeau | last post by:
Hello, I am trying to craft a regular expression to filter an URL from a <a href=""></a> tag and the one I have doesn't seen right. I use the regular expression from this snippet of code: ...
2
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display...
1
by: chotiwallah | last post by:
this is the html: <a href="Javascript:change();">change</a> <object data="a.htm" type="text/html" width="200" height="200" id="obj"></object> and this the javascript:
6
by: snacktime | last post by:
I've searched and searched and have not found a solution to suppress the margin on form or href tags so that there is no space before or after the tag. The only way I have found to do this is to...
2
by: Gabriel Lozano-Morán | last post by:
Is there a reason why this does NOT work in IE6.0 ? <html> <head> <style type="text/css"> a { text-decoration: none; } a:hover
3
by: Reinhold Schrecker | last post by:
Hi there, I am trying to generate a dynamic menu with JavaScript/DOM and have problems to set the onclick-attribute for my <a>-elements. The following code works fine in Opera and Mozilla but...
3
by: ajos | last post by:
Hello friends, In my action class i am getting a resultset data which im storing in a arraylist. In my jsp page im retrieving the arraylist data as-----> <%publicity.PendingReqForm prfObj=null;...
5
by: SKbirdie | last post by:
I have an existing website using Speedscript which is like Progress code. I have to put the includes and variables in the speedscript but need to do an <a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.