[英]Element.getElementByTag(“mytag”) sometimes returns empty
CKeditor Element1's outer html as below: CKeditor Element1的外部html如下:
<element1 id="s1">
<mytag>Test1</mytag>
<span> </span>
Some text
<mytag>Test</mytag>
<span> </span>
<mytag>Test3</mytag>
some text
<span> </span>
</element>
var element1=EditorIns.document.getById("s1");
EditorIns.focus();
var mt=element1.getElementsByTag("mytag");
alert(mt.count());
Normally it's working fine, but sometimes mt.count()
is 0. 通常它可以正常工作,但有时mt.count()
为0。
I also tried with jQuery like this: 我也尝试过使用jQuery,如下所示:
$(element1.$).find("mytag").length;
It also has the same problem. 它也有同样的问题。 Please help me out from this issue 请帮我解决这个问题
Write the code in a function And call this function same as following :-
<script type="text/javascript">
function testElement(){
var element1=EditorIns.document.getById("s1");
EditorIns.focus();
var mt=element1.getElementsByTag("mytag");
alert(mt.count());
}
window.onload=testElement;
</script>
The element is loading after complete the page load and window.onload will call when all the elements completely loaded on the page.
or 要么
$(element1).find("mytag").length;
if element1
is a regular html element 如果element1
是常规html元素
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.