2016-10-11 10 views
-2

私はちょうど私の頭を丸くすることはできませんが、私はそれがちょうど良い得るための全体的な目的を破るだろう問題のビットを持っています。だから、私はすべて同じクラス名を持つ要素のセットを持っていると言われていると私はそれが私にクリックされたその親の中の要素を取得するボタンを選択したい。親要素を取得するjavascript

<article class="col-xs-12 col-sm-3"> 
<a href="http://79.170.43.200/shaveandsubscribe2.co.uk/shaveandsubscribe2/index.php/gillette-fusion-proshield.html?___SID=U"> 
<h3>Gillette Fusion ProShield</h3> 
<pid class="temp_pid" style="display:none;">366730415</pid> 
<pid2 class="temp_pid" style="display:none;">373545146</pid2> 
<pid3 class="temp_pid" style="display:none;">373546370</pid3> 
<img src="http://79.170.43.200/shaveandsubscribe2.co.uk/shaveandsubscribe2/media/catalog/product/cache/1/image/265x/9df78eab33525d08d6e5fb8d27136e95/g/i/gillette-fusion-proshield.jpg" alt="Gillette Fusion ProShield" class="img-responsive"> 
</a> 
    <div class="1" style="display:none;"> 

    <button type="button" id="1" title="Proceed" class="button btn-cart" onclick="getUrl(this.id);"><span><span>Proceed</span></span></button> 

    <input type="hidden" id="x1" class="rrp_price" name="rrp_price" value="$19.4900"> 

    <input type="hidden" id="y1" class="spcl_price" name="spcl_price" value="$19.4900"> 

    </div> 

    <button class="price-change" id="1" value="£19.49" name="£19.49" onclick="getSet(this.id);">Select</button> 



    </article> 

私が取得しようとしていますクラスは、「temp_pid」今、私は上記のコードは分で効果的にその3つのたくさんあります持っている私のスクリプトは、合計で9

あるtemp_pidクラスのすべてのを取得することです
jQuery('body').on('click','.price-change',function(){ 
localStorage.removeItem('priceChange'); 
localStorage.setItem('priceChange', "priceChange"); 
// alert(localStorage.getItem("priceChange")); 

// cratejoy script to capture product ids aka <pid> etc... 
if(jQuery('.price-change').hasClass('selected')){ 
var x = document.getElementsByClassName('temp_pid'); 
for(var i = 0; i < x.length; i ++){ 
    console.log(x[i].innerHTML); 
} 

}; 

}); 

答えて

0

私はそれが動作することを願って親の中の要素を選択します。

関連する問題