我需要的部份子节点的父节点获取父节点元素
这是我当前的代码
console.log (($(editor.selection.getNode()).parent()[0]));
这将返回类似这样的
<ol>....</ol>
但什么一些事情我需要的只是赶上Ol元素
所以任何人都可以帮忙?
我需要的部份子节点的父节点获取父节点元素
这是我当前的代码
console.log (($(editor.selection.getNode()).parent()[0]));
这将返回类似这样的
<ol>....</ol>
但什么一些事情我需要的只是赶上Ol元素
所以任何人都可以帮忙?
如果我理解正确,您正在尝试获取标记名称。您可以使用tagName属性从元素中获取标签名称。试试这个
console.log (($(editor.selection.getNode()).parent()[0].tagName));
感谢Tamillharasan – ChamZ
<ol id="h1">
<li>I</li>
<li>II</li>
</ol>
<ol id="h2">
<li>I</li>
<li>II</li>
</ol>
$(document).ready(function() {
$('li').click(function(){
alert($(this).parent().attr('id'));
$(this).parent().css('background-color', 'red');
});
});
你能告诉我们你的HTML请求吗? – krishgopinath
@Chanmz“我需要的只是赶上Ol元素”的意思? – Praveen
听起来像是一样的东西......'ol元素只有'和'
...
' – MikeM