dynamically adding a css class to a div/span [duplicate]
Possible Duplicate:
Add another class to a div with javascript
How can i dynamically add/remove a class to a span?
Set the property 'className' on the span. This will set its css class
Well, you could use jQuery to manipulate the span.
<span></span>
<script type="text/javascript">
$("span").addClass("addedClass");
$("span").removeClass("addedClass");
</script>
You could use PHP to change the class. Using some sort of link to link between different php instances.
Here would be the "button":
<div class="info_tab">
<p><?php if($_GET['state'] !='1') echo '<a href="?state=1">click to change class</a>'; else echo '<a href="page.php">click to change class back</p>' ?></p>
</div>
Here would be the changing span:
<span <?php if(isset($_GET['state']) && $_GET['tab'] == 1) echo 'class="state1"'; else echo 'class="state2"';?>>More information</span>
It's nice to have a non-javascript way for compatibility reasons for some users.
精彩评论