2013-10-18 88 views
0

我與這個Jquerygraphdracula工作,我有這樣的觀點:選擇在jQuery庫特定的標籤

view

html代碼code

<script> 
     $.fn.changeElementType = function (newType) { 
      var attrs = {}; 

      $.each(this[0].attributes, function (idx, attr) { 
       attrs[attr.nodeName] = attr.nodeValue; 
      }); 

      this.replaceWith(function() { 
       return $("<" + newType + "/>", attrs).append($(this).contents()); 
      }); 
     }; 
</script> 
<script type="text/javascript"> 
    $(function() { 
     $("#canvas").changeElementType("a"); 
     // Now you probably want to add an href 
     $('a').attr('href', 'http://www.google.com'); 
    }); 
    </script> 

我想只選擇標題(F2,la fonction une ...)而不是孔div元素。我嘗試:

$("text").changeElementType("a"); 

$("tspan").changeElementType("a"); 

但是我有這個視圖(無圖)。

error

那麼,什麼是這個錯誤的原因是什麼?如何修復我的代碼以選擇標籤並將其更改爲超文本鏈接?

+1

什麼是你得到的錯誤?你可以發佈HTML後的圖表? – Snuffleupagus

+2

你確定這是正確的jsfiddle鏈接嗎?它沒有任何與這個問題有關的東西。 – Barmar

+0

@Barmar對不起,我把錯誤的鏈接,我更新:) –

回答

1

也許這是你想要什麼:

$("#canvas tspan:contains(la fonction une)").changeElementType("a"); 
+0

沒有抱歉,相同的結果 –