2013-11-25 26 views
0
<table id="addressbook" > 
     <thead> 
      <tr> 
       <th>Company</th> 
       <th>Documentation Address</th> 
       <th>Type</th> 
      </tr> 
     </thead> 

     <tbody> 
      <tr id="table-row_1"> 
       <td>Gigi World</td> 
       <td>Cresent Road 
       </td> 
       <td class="type-column"><span class="company-type">Shipper</span><br> 
        <span class="update-link"> <a data-code="11301181" id="Shipper" data-toggle="modal" role="button" class="rate update-anchor" href="#update-addresstype">Update</a> 
       </span> <span id="delete-link" class="pull-right delete-link"> <a href="#" class="view-all">Delete</a></span> 
       </td> 
      </tr> 
     </tbody>  
    </table> 

表可以有多行相同的類型。jquery:替換表列內的span的內容

$(".update-link").click(function() { 

    var elem = $(this).closest('tr'); 
}); 

一些操作後,我要選擇此perticular trthird td (class name ="type-column"),並希望與我自己的價值,以取代first span (class name ="company-type")的內容可以說(例如,世界您好)

我試圖

elem.find("td:eq(2)").text("Hello World"); 

但它不工作。幫我!!

編輯: 更新jsfiddle here

+0

是在'情商缺失的圓括號(2'只是一個錯字在你的代碼示例或它實際上是在你的產品代碼 – matewka

回答

2

你從來沒有關注span

elem.find("td:eq(2)").find("span.company-type").text("Hello World"); 
0

你在你的代碼有幾個錯別字。選中此更新:http://jsfiddle.net/V85Vx/29/

$(".update-link").click(function() { 
    alert("update clicked") 
     var elem = $(this).closest('tr'); 
     elem.find("td:eq(1)").text("Hello World"); 
    }); 
+0

我想替換第三列的內容呢?第二列 – maaz

+0

第三列已經有3個跨度了..我想替換第一個跨度的內容 – maaz

+0

好吧,我剛剛走過你的小提琴。試着在第三列的第一個跨度:'elem.find(「td: eq(2)span:eq(0)「)。text(」Hello World「);' – andi