VeloFX VeloFX - 5 months ago 26
Javascript Question

js Jquery .text() doesn't work

i've got this js-code:

$(".dpst_item").click(function(){
var dpst_id = this.id;
var text = $('img.'+dpst_id+' span.dpst_item_span').text();
alert(text);
}):


And this php-code:

echo '<div class="dpst_item_div"><img id="' . $item_classid . '" class="dpst_item" class="dpst_item-select" src="https://steamcommunity-a.akamaihd.net/economy/image/class/730/' . $item_classid . '/102fx102f" title="' . $item_name . '" ><span id="' . $item_classid . '_price" class="dpst_item_span" style="cursor:pointer">'.$item_price.'$</span></div>';


But i dont get anything at alterted.

Answer

I think you are trying to get the span element next to the clicked img tag then you can use next() method to get it.

$(".dpst_item").click(function(){
    var text = $(this).next().text();
    alert(text);
}):
Comments