2013-12-09 50 views
1

我有一個自定義標籤。我想使用jquery爲該自定義標籤設置值。 雖然這看起來很愚蠢,但我花了更多時間搜索結果。使用jquery獲取自定義標籤(包含冒號)值

我的標籤是

<error:description code="12345" type="error" result="description" />${description} 

現在我想拿到代碼,並通過使用jQuery的值。

請幫助我如何做到這一點。

我沒有things i tried area,因爲我甚至不知道如何開始。

在此先感謝

回答

7

你需要逃避使用兩個回斜線結腸,所以只是做

$('error\\:description').attr("result"); //to get result attribute 
$('error\\:description').text(); //to get the related text 
+0

其給予undefined $('error \\:description')。attr(「result」); –

+0

@MonickaAkilan它的工作原理,請參閱http://jsfiddle.net/fY55k/ –

3

我想這應該這樣做:

jQuery("error\\:description").text("your text"); 
+0

它不工作 –

+0

我嘗試了它,它對我來說工作得很好。 'jQuery(「error \\:description」)'發現''元素。 – PKeidel