473,738 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Attribute to HTML Tag <a href=

30 New Member
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 6066
nothing1
30 New Member
Looking over the Javascript code for getElementByCla ss it seems like i might not even need the replace function if the getElementByCla ss 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 Recognized Expert Moderator MVP
Try:
Expand|Select|Wrap|Line Numbers
  1. allPageTags[i].setAttribute("rel","lightbox");
Jan 10 '08 #3
nothing1
30 New Member
thanx! worked perfectly.
Jan 11 '08 #4
acoder
16,027 Recognized Expert Moderator MVP
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
8772
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: foreach my $message (@messages) { my @match=($message->decoded=~/\bhref="(http.*)">.*/gi);
2
9171
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 in the status bar 'Symantec Corporation' whenever anyone mouses over (onMouseOver) my image or link OR when one clicks while holding the left mouse down (onClick) on the same image or link. Upon releasing the mouse (onMouseOut), the
1
9088
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
3873
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 place the tags one after another without any spaces between them. For example, a space gets rendered between these two href's when displayed in firefox or IE. <a href="#"><img border="0" height="10" src="test.gif" width="10" /></a>
2
2857
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
14900
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 does not work in IE: <!--snip--> <script language="JavaScript">
3
2125
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; ArrayList req=(ArrayList) request.getAttribute("req"); for(Iterator it= req.iterator();it.hasNext();){ prfObj=(PendingReqForm) it.next();{ %>
5
2601
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 href="WI_testweb/"+variable+".xml">Matrix</a> the variable value should be our customers number which will be the name of the .xml spreadsheet. I appreciate any and all help. thanks,
0
8968
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9473
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.