2014-01-22 39 views
0

更換特定的詞我有一個簡單h2元素,看起來像這樣:在h2元素

<h2>New Agent - Record Status: 
    @Html.DisplayFor(model => model.RecordDisplayStatus)           
</h2> 

當用戶點擊一個按鈕,我需要能夠在那裏更改單詞AgentAgency。這是我第一次嘗試,但我不斷收到以下消息:

Uncaught TypeError: Object [object Object] has no method 'replace' 

這是我的第一次入侵它

$('.head h2').replace("Agent", "Agency"); 

回答

2

那是因爲你正試圖打電話replace一個jQuery對象。你需要調用replace上的繩子,所以試試這個:

var newval = $('.head h2').text().replace("Agent", "Agency"); 
    $('.head h2').text(newval); 

而一個fiddle

相關問題