loops - Using JavaScript (jQuery), how can I cycle through all 'a' tags on a page, one at a time, and assign an individual style to each? -
Try to explain to me ... let's say that I have the following 'A' tag on a page:
& lt; A href = "img1.jpg" class = "myClass" alt = "0,0,600,200" & gt; & Lt; / A & gt; & Lt; A href = "img2.jpg" square = "miracles" alt = "200,0,600,75" & gt; & Lt; / A & gt; & Lt; A href = "img3.jpg" square = "myClass" alt = "275,0,600,200" & gt; & Lt; / A & gt; & Lt; A href = "img4.jpg" square = "myClass" alt = "475,0,600,50" & gt; & Lt; / A & gt; & Lt; A href = "img5.jpg" square = "miracles" alt = "525,0,600,100" & gt; & Lt; / A & gt; & Lt; A href = "img6.jpg" square = "miracles" alt = "625,0,600,200" & gt; & Lt; / A & gt;
And I want to cycle through the class 'myClass' through all the 'A' tags and read alt tags and specify specific 'style' attributes depending on its value. I do
I tried the following:
But this first assumes the 'A' tag as 'alt' attribute and specifies the style on all 'A' tags. What I'm trying to do, read every 'A' tag, get the 'Alt' value and assign to the style that 'A' tag reads only the next 'A' tag ...
Is there a way to accomplish this without providing a unique ID or class for an 'id'?
I'm totally new to jQuery and have tried this issue and spent hours and can not figure out how.
Any help please
You can use the method like this:
$ ('A.myClass') Each (function () {var tmp = $ (this) .attr ('alt'); // your next code ...});
will be repeated on all links with each
class myClass
and the alt
value of each link will be stored The tmp
variable that you can work on.
Comments
Post a Comment