2014-04-01 45 views
0

我想要刪除父ID屬性添加的特定效果。如何刪除父ID作用

<div id="js-item-notifymebtn-$item.itemid" style="display:none;"> 
     <div id="notifyComment"> This item is out of Stock 
     </div> 
     <div class="btnclass addToCartBtn"> 
      <a class="btn-notify"> 
      <span>#springMessage('vm.wishlist.notifyme.button')</span> 
      </a> 
     </div> 
    </div> 

這裏我添加的「此商品缺貨」的消息即將作爲按鈕。任何人都可以幫助我解決如何使其成爲普通文本。

我加入了JavaScript代碼這樣

<script> 
    $(document).ready(function() { 
     $("#notifyComment").removeAttr("id"); 
    }); 
</script> 

刪除id屬性的onload,但沒有得到所需的結果。

+0

向我們展示了一個小提琴問題。這應該工作。這裏是工作小提琴http://jsfiddle.net/Y9etS/ –

+0

你應該使用一個類,然後用'$ .removeClass('。name_of_the_class''' – Biduleohm

+0

''刪除它但是我的情況不能改變id,因爲它正在許多其他地方使用。並且按鈕效果正在被id(id =「js-item-notifymebtn- $ item.itemid」)添加 – Santosh

回答

0

如果我理解正確的話這應該工作:

$(document).ready(function() { 
    $("#notifyComment").parent().removeAttr("id"); 
}); 

JSFiddle

0

但ID不能在我的情況下被改變,因爲它在其他許多地方被使用。並且按鈕效果被id添加(id =「js-item-notifymebtn- $ item.itemid」)

您必須決定是否要解決您的問題。如果你創建一個omlette,你將不得不打破幾個雞蛋。讓你的效果依賴於一個類而不是一個ID,修復你的依賴關係,然後使用類似於

$(document).ready(function() { 
    $("#notifyComment").removeClass("myClass"); 
}); 
+0

嗨,這裏的問題是不改變id =「notifyComment」到class =「notifyComment」。但我不能將id =「js-item-notifymebtn- $ item.itemid」更改爲class =「js-item-notifymebtn- $ item.itemid」。基本上按鈕效果是由id =「js-item-notifymebtn- $ item.itemid」添加的。 – Santosh

+0

我編輯了我的答案,我的代碼是垃圾,對不起。您需要刪除類(例如myClass),當您需要擺脫效果並修改依賴關係取決於您的類名而不是id。請注意,ID是存在的,所以可能是其他依賴不會被破壞的情況。 –