2015-01-16 4 views
0

replaceWith를 사용하여 버튼을 다른 태그로 바꾸는 데 문제가 있습니다. 내 코드 : 버튼의 HTML 및 클래스는 HTMLButtonElement입니다 :JQuery replaceWith in Coffeescript

버튼을 클릭 할
<button name="button" type="button" class="join-button" 
     data-player="1">Join Game!</button> 
buttonToText = (element) -> 
    console.log(element) 
    element.replaceWith("<h1>hi</h1>") 

$ -> 
    $(".join-button").on click: -> 
    buttonToText(this) 

, CONSOLE.LOG 올바른 값을 반환 나타납니다. 그러나 replaceWith 행에 Uncaught Type Error: Undefined is Not a Function 이 표시됩니다. 오류가 발생하는 이유는 무엇입니까? 차이가 나는 경우 Rails 4.2가 실행 중입니다.

+0

$(this) 또는 element 요구로, replaceWith은 요소에 대해') Object.getOwnPropertyNames'의 목록 (있는 것으로 표시되지 않습니다, 그래서 내가 사용할 수 없습니다 추측 여기로 대체 하시겠습니까? – Ativ

+1

콜백의'this'가 DOM 노드일까요? 그러나 [replaceWith'] (http://api.jquery.com/replaceWith/)는 표준 DOM 노드 함수가 아닌 * jQuery * 함수입니다. 아마도'$ (element)'가 더 유용 할 것입니다. –

+0

당신이 있습니다! 'this (이)'또는'$ (요소)'대신'$ (this)'가 작동합니다! 감사! – Ativ

답변

0

this 요구 또한 $(element)