Created
August 23, 2012 03:35
-
-
Save geta6/3431925 to your computer and use it in GitHub Desktop.
access to :before or :after objects using javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<link rel='stylesheet' href='style.css'> | |
</head> | |
<body> | |
<div id='target'></div> | |
<input id='button' type='button' value='click'> | |
<script src='script.js'></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var target = document.getElementById('target') | |
, button = document.getElementById('button'); | |
button.addEventListener('click', function () { | |
target.setAttribute('data-content', 'this is before content'); | |
}, false); | |
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#target:before { | |
display: block; | |
content: attr(data-content); | |
width: 160px; | |
height: 90px; | |
color: white; | |
background: red; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment