Created
September 8, 2013 06:15
-
-
Save takkyuuplayer/6482355 to your computer and use it in GitHub Desktop.
今更ながらcss selector における nth-of-type を知った。nth-childよりも使いやすい
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="utf-8" /> | |
<title></title> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<table border="1"> | |
<tr id="row1"><th>nth-child(2)</th><td>1</td><td>2</td><td>3</td></tr> | |
<tr id="row2"><th>nth-type-of(2)</th><td>1</td><td>2</td><td>3</td></tr> | |
</table> | |
<script> | |
jQuery(function($){ | |
$('table tr#row1 td:nth-child(2)').css('background-color', 'pink') | |
$('table tr#row2 td:nth-of-type(2)').css('background-color', 'pink') | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment