jQuery를 사용하지 않고 다음 세 요소에서 Some Text
, <a href="abc.html">Some Anchor</a>
및 <img src="abc.jpg" />
을 어떻게 반환합니까? 즉, jQuery를 사용하지 않고 $('#t1).text()
, $('#t2).text()
, $('#t3).text()
을 어떻게 반환할까요? 한 번에 하나의 요소 만 선택하므로 여러 요소가있는 경우 배열을 반환 할 필요가 없습니다.하나의 선택된 요소에 대한 텍스트의 네이티브 JavaScript equivilent
<td id="t1">Some Text</td>
<td id="t2"><a href="abc.html">Some Anchor</a></td>
<td id="t3"><img src="abc.jpg" /><td>
jQuery는 다음과 같이 text()를 수행합니다. 여러 요소에 대한 배열을 반환하는 것에 대해 걱정하지 않으므로 잔인한 것으로 보입니다.
text: function(value) {
return jQuery.access(this, function(value) {
return value === undefined ?
jQuery.text(this) :
this.empty().append((this[0] && this[0].ownerDocument || document).createTextNode(value));
}, null, value, arguments.length);
},
감사
당신은 노드 (들)의 텍스트를 검색과 같이 할 수
'$ ('#의 T2')''일부 Anchor'가 아닌'
Can you just read the 'innerHTML' property after using 'document.getElementById()'? –
@CrazyJugglerDrummer. No, it will only work for the and , not the text node. – user1032531