Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Rel attribute value

Tags:

jquery

I have a page with multiple occurrences of an element with class of .gal_link, such as

<a href="" rel="shadowbox[gallery32];height=545;width=805" title="">Blah Blah</a>

What I am trying to do is find all occurrences of this on the page, and update the height and width to something like

<a href="" rel="shadowbox[gallery32];height=345;width=605" title="">Blah Blah</a>

I would imagine this should be easy but after searching high and low I can not find a straight forward way to do this. Any help would be appreciated.

I was able to alert the rel for each link upon a click but can't see how to change attribute values once the page has loaded.

$('.gal_link').click(function(){
    var rel = $(".gal_link").attr('rel');
    alert(rel);
});

Again thanks.

like image 378
TMHDesign Avatar asked Aug 29 '13 17:08

TMHDesign


People also ask

How do you find rel value?

Using document. In JavaScript, the document. getElementsByTagName() method can be used to get the value of the rel attribute of a link or anchor tag. It takes a tag name in the parameter and returns an HTMLCollection, similar to a list or array.

What is rel attribute in css?

The rel attribute specifies the relationship between the current document and the linked document. Only used if the href attribute is present. Tip: Search engines can use this attribute to get more information about a link!

What is the full form of rel in HTML?

The HTML <form> rel attribute is used to define the relationship between the current document and the linked document. The “rel” stands for relationship. It denotes that, we connect an external CSS with the HTML page. Syntax: <form rel="value">


1 Answers

Pass value you want to assign to attribute in second argument of attr( attributeName, value )

$("selector").attr('rel', 'somevalue');
like image 137
Adil Avatar answered Sep 28 '22 03:09

Adil