2014-01-08 92 views
0

我想將alt值​​添加到特定div內的所有錨標記。 我需要循環div並找到錨標記並添加alt值。 結構如下像下面將alt值​​添加到div內的所有錨標記

<div id="ctl00_MenuTreeView" style="font-size:11px;"  onadaptedselectednodechanged="OnNodeSelected"> 
<table cellspacing="0" cellpadding="0" style="border-width:0;"> 
<tbody> 
<tr> 
<td> 
<td class="TreeViewNode ctl00_MenuTreeView_2 ctl00_MenuTreeView_6"  onmouseout="TreeView_UnhoverNode(this)"  onmouseover="TreeView_HoverNode(ctl00_MenuTreeView_Data, this)"> 
<a id="ctl00_MenuTreeViewt0" class="ctl00_MenuTreeView_0 TreeViewNode  ctl00_MenuTreeView_1 ctl00_MenuTreeView_5" style="border-style:none;font-size:1em;"  title="Home Page" onclick="TreeView_SelectNode(ctl00_MenuTreeView_Data,  this,'ctl00_MenuTreeViewt0');"  href="javascript:__doPostBack('ctl00$MenuTreeView','s/wotc/Default.aspx')">Home</a> 
</td> 
</tr> 
</tbody> 
</table> 
<table cellspacing="0" cellpadding="0" style="border-width:0;"> 
<table cellspacing="0" cellpadding="0" style="border-width:0;"> 
<table cellspacing="0" cellpadding="0" style="border-width:0;"> 
<table cellspacing="0" cellpadding="0" style="border-width:0;"> 
</div> 

感謝 亞歷

+0

你不需要做任何的循環。到目前爲止,您試過的JavaScript在哪裏? –

+0

我如何添加alt錨定標籤內部的所有表格元素內,菜單項是從asp.net treeview控件動態創建的 – user2217726

+1

http://api.jquery.com/attr –

回答

0
function OnTreeViewLoaded() { 
    $('#ctl00_MenuTreeView .TreeViewNode a').attr('alt', 'whatever'); 
}