The answer to your IT questions
 

Advanced search  • Search tips
My QUESTIONS & ANSWERS
 Question:

Remove attributes from elements?

User Asked by: alexander
Published on: 10:33/14.01.2008
Status: OPEN
How can i remove one kind of attributes (like 'class') in a block
Example:

<div id="links">
  <a href="#" class="links">link1</a>
  <a href="#" class="links">link1</a>
  <a href="#" class="links">link1</a>
</div>


Additional info by autor:
The point is to make it with event, like "onclick", to check if there is attribute "class" to remove it.
 Answers: 2
Sort by: /\ date | rating
Image Answer by: milen
Posted on: 10:14/10.01.2008
Rating: 1 from possible 5 with 4 votes
You can apply style to all <a> tags:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Test</title>
		<style>
			#menu a{
				color:green;
			}
		</style>
	</head>
    <body>
        <ul id="menu">
            <li><a href="#">link 1</a></li>
            <li><a href="#">link 2</a></li>
            <li><a href="#">link 3</a></li>
        </ul>      
    </body>
</html>
Vote:

Image Answer by: xpert
Posted on: 10:33/14.01.2008
Rating: 1 from possible 5 with 4 votes
I think probably you ask for removeNamedItem() method on attributes collection of each HTML element.
The sample below works fine on IE, FireFox, Opera, Safari and probably others.



<html>
<head>
    <style>
    .links{
        color:green;
        font-weight:bold;
    }
    </style>
</head>    
<body>
    <div id="links">  
    <a href="#" class="links" 
        onclick="this.attributes.removeNamedItem('class')">link1</a>  
    <a href="#" class="links" 
        onclick="this.attributes.removeNamedItem('class')">link1</a>  
    <a href="#" class="links" 
        onclick="this.attributes.removeNamedItem('class')">link1</a>
    </div>
    <div 
        onclick="this.attributes.removeNamedItem('title')" 
        title="My tooltip">
        When you click this DIV ToolTip will be inactivated.
    </div>
</body>
</html>
Vote:

Please vote! Your opinion matters!
If you haven't found what you've looking for, post a question
  
| Home | Hall of fame | Register | Log in | Terms of service | Help | Contacts |