Jump to content

removeAttribute on all anchors

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

removeAttribute on all anchors Rate Topic: -----

#1 User is offline   temhawk 

  • W.R. Private First-Class
  • Group: Members
  • Posts: 322
  • Joined: 30-August 07
  • Gender:Male
  • Interests:travel, cg art, macs, music, skateboarding, programming, discovery channel, TextMate 2

Posted 30 July 2008 - 04:07 AM

Hey, I am stuck here. I want to remove an attribute from all links of a page, but I can't figure it out.

I found the removeAttribute function, but I don't know how to select all <a> elements in the whole page with as little code as possible.

This is what I have so far:
	<!--[if IE 6]>
		<style>
			* html #mica-container img, * html #mica-container div, * html #mica-container a {
				behavior: url(ebay/template/iepngfix.htc);
			}
		</style>
		<script type="text/javascript">
			document.getElementsByTagName('img').removeAttribute('alt');
		</script>
	<![endif]-->


I'm doing this because IE sucks and IE 6 has the stupid alt text displayed on top of the images with the HTC file to fix transparent PNGs.

Unbelievable they are making IE 8 btw, I wished they would just keep their mouths and IE development shut. The IE Blog is a real flip off, makes me sick to read about their "mission" and how they are doing so many good things to the browser to promote "Trustworthy Computing". Ok, I stop the rant now.

Help would be appreciated here! Thanks...
0

#2 User is offline   TJSingleton 

  • Allegedly Legendary
  • Group: Members
  • Posts: 517
  • Joined: 31-July 06
  • Location:Winder, GA

Posted 30 July 2008 - 09:57 AM

Have you tried just assigning the image a blank title?

<img src="rocking-cool-animated.gif" alt="Text you don't want displayed" title="" />

This post has been edited by TJSingleton: 30 July 2008 - 09:59 AM

0

#3 User is offline   temhawk 

  • W.R. Private First-Class
  • Group: Members
  • Posts: 322
  • Joined: 30-August 07
  • Gender:Male
  • Interests:travel, cg art, macs, music, skateboarding, programming, discovery channel, TextMate 2

Posted 30 July 2008 - 10:26 AM

View PostTJSingleton, on Jul 30 2008, 04:57 PM, said:

Have you tried just assigning the image a blank title?

<img src="rocking-cool-animated.gif" alt="Text you don't want displayed" title="" />

Yeh, it doesn't work.

IE even has inconsistencies within its inconsistencies. - . -
0

#4 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 30 July 2008 - 02:52 PM

js won't automatically iterate through the returned array like you're trying
you need to call the getAllElements and then do a for or for each loop through the array it sends back doing the remove
or use jquery of course
0

#5 User is offline   temhawk 

  • W.R. Private First-Class
  • Group: Members
  • Posts: 322
  • Joined: 30-August 07
  • Gender:Male
  • Interests:travel, cg art, macs, music, skateboarding, programming, discovery channel, TextMate 2

Posted 30 July 2008 - 03:30 PM

View PostCatalyst, on Jul 30 2008, 09:52 PM, said:

js won't automatically iterate through the returned array like you're trying
you need to call the getAllElements and then do a for or for each loop through the array it sends back doing the remove
or use jquery of course

Thanks, I get what you're saying. I'll try my luck tomorrow!
0

#6 User is offline   Rob Kaper 

  • W.R. Corporal
  • Group: Members
  • Posts: 97
  • Joined: 19-July 08
  • Gender:Male
  • Location:Rotterdam, NLD

Posted 03 September 2008 - 07:14 AM

In jQuery:

$('a > img').removeAttr('alt');


Removes the 'alt' attributes of all images inside an anchor tag.

In regular:

var images = document.getElementsByTagName( 'img' );
for ( var i=0; i<images.length; i++ )
  images[i].removeAttribute( 'alt' );


Remove the 'alt' attribute from every image.

This post has been edited by Rob Kaper: 03 September 2008 - 07:14 AM

Rob Kaper - Rotterdam
0

#7 User is offline   temhawk 

  • W.R. Private First-Class
  • Group: Members
  • Posts: 322
  • Joined: 30-August 07
  • Gender:Male
  • Interests:travel, cg art, macs, music, skateboarding, programming, discovery channel, TextMate 2

Posted 03 September 2008 - 01:42 PM

Thank you. I passed the challenge/project on to someone else already. I still appreciate your help though!!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users