複数の属性値を取得するにはどうすればよいですか? 正しく取得できhref
、 も取得したいのですがalt
、正しく理解できず、正しい結果が得られません。私.attr('href').attr('alt')
.attr('href' + 'alt')
も試してみましたが.attr({href, alt})
、
オンライン サンプルは次のとおりです: http://jsfiddle.net/Lm4TM/
JS:
$(document).ready(function(){
$(".link").each(function (i) {
var links = $(this).find("a");
$(this).wrapInner("<a href='"+ $(links).attr('href') + "'></a>");
});
});
CSS:
.link {
width:20%;
height: 100%;
background: red;
float: left;
margin: 0 20px;
}
a {
text-decoration: none;
color: white;
}
HTML:
<div class="link">
<a href="http://www.google.com" alt="google">Google.com</a>
<p> Google Inc. is an American multinational corporation that provides Internet-related products and services, including internet search, cloud computing, software and advertising technologies.Advertising revenues from AdWords generate almost all of the company's profits</p>
</div>
<div class="link">
<a href="http://www.microsoft.com" alt="microsoft">Microsoft.com</a>
<p>Microsoft Corporation is an American multinational software corporation headquartered in Redmond, Washington that develops, manufactures, licenses, and supports a wide range of products and services related to computing.</p>
</div>
<div class="link">
<a href="http://www.Apple.com" alt="Apple">Microsoft.com</a>
<p>The apple is the pomaceous fruit of the apple tree, species Malus domestica in the rose family (Rosaceae). It is one of the most widely cultivated tree fruits, and the most widely known of the many members of genus Malus that are used by humans.</p>
</div>