2016-03-21 7 views
-3

前に、要素から属性を削除するここでは私のコードjQueryの現在の

<a target="_blank" href="/pics/2016/03/21/56efb593855ae56efb5938599556efb59385d80.jpg" title="Click For Larger View"> 
<img src="/pics/2016/03/21/56efb593855ae56efb5938599556efb59385d80.jpg" width="150px" height="150px" id="post-img" class="post-img"> 
</a> 

です.post-imgクラス以上の要素からhref要素を削除取得するためのjQueryので方法はあります。

だから理論的には私はそれはのように判明します:

<a target="_blank" title="Click For Larger View"> 
<img src="/pics/2016/03/21/56efb593855ae56efb5938599556efb59385d80.jpg" width="150px" height="150px" id="post-img" class="post-img"> 
</a> 

、これを行うことができます。要素のクラス(.post-img)をa(リンク)の内部に入れるだけです。

!!!これはできますか?

JavascriptまたはJqueryで私がうまくいけないことを教えてください。

+0

http://www.w3schools.com/jsref/met_element_removeattribute.aspをチェック – Tibrogargan

答えて

0

parent()メソッドを使用して親を取得し、removeAttr()を使用してhrefを削除します。

$('.post-img').parent().removeAttr('href');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<a target="_blank" title="Click For Larger View" href="/pics/2016/03/21/56efb593855ae56efb5938599556efb59385d80.jpg"> 
 
    <img src="/pics/2016/03/21/56efb593855ae56efb5938599556efb59385d80.jpg" width="150px" height="150px" id="post-img" class="post-img"> 
 
</a>

関連する問題