in Advanced 

Question preview

HomeQuestion preview:
Log in

Remove attributes from elements?

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.
Do you know someone who could answer? Ask him for help
Answers: 2
Sort by: date rating
image milen
12:14/10.01.2008
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 xpert
12:33/14.01.2008
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
Ask question
| Home | Hall of fame | Registration | Log in | Terms of service | Privacy policy | Help | Contacts | RSS |