5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScript自分メモ

Posted at

#jQueryで、特定の属性の特定の値を持つ値の取得。

<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<meta charset="UTF-8">
<title>This is Template</title>
<!--<link rel="stylesheet" type="text/css" href="example.css">-->
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
    // クラスの場合は下記の両方OK
    // 結果は"2-Text"
    console.log($('.myclass [hoge=2]').html());
    console.log($('ul.myclass [hoge=2]').html());

    // IDの場合はこう
    // 結果は"3-Text"
    console.log($('#yourclass [hoge=3]').html());
});
</script>

<style type="text/css">
</style>
</head>
<body>
<ul class="myclass">
    <li><a hoge="1" href="Javascript:void(0)">1-Text</a></li>
    <li><a hoge="2" href="Javascript:void(0)">2-Text</a></li>
    <li><a hoge="3" href="Javascript:void(0)">3-Text</a></li>
</ul>
<ul id="yourclass">
    <li><a hoge="1" href="Javascript:void(0)">1-Text</a></li>
    <li><a hoge="2" href="Javascript:void(0)">2-Text</a></li>
    <li><a hoge="3" href="Javascript:void(0)">3-Text</a></li>
</ul>

</body>
</html>
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?