2014-04-12 73 views
0

Iam具有以下表格結構。查找div元素並使用jquery替換value-innerhtml

HTML: 
<table> 
<tr> 
    <td> 
    <img id='imgScheduled' onclick='start();'/> 
    </td> 
    <td> 
    <div class='divStatus'>Scheduled</div> 
    </td> 
</tr> 
</table> 
..Same table structure repeated 

上面的表是動態定義的,其中img ids也是動態生成的。我想改變點擊img的divStatus值,它具有一些功能,即狀態需要像使用jQuery一樣更改爲「inprogress」,就像$(「#imgid」)。最接近的東西,我不確定。

+0

img'元素是否有可預測的模式? –

回答

1

綁定在圖像上單擊,並找到.divStatus,然後更改其內容!

記住的.text()將協商而不是html的(),將呈現DOM元素你的說法,!

http://jsfiddle.net/XL5Ew/

$(function() { 
    $(document).on('click', '#imgScheduled', function (e) { 
     $(this).parent().parent().find('.divStatus').text('in progress...'); 
     // Or with elements 
     $(this).parent().parent().find('.divStatus').html($('<span>').text('in progress...')); 
    }); 
}); 
+0

你打我! :) –

+0

不長,我想:) –

+1

它錯了你有沒有測試過這個小提琴 –

3

怎麼樣這個?

$('body').on('click','td > img',function(){ 
    $(this).closest('tr').find('.divStatus').html('in progress..'); 
}); 
+0

它錯了,它不會工作 –

+0

爲什麼因爲你的工作? –

+0

你可以在小提琴中測試 –