简体   繁体   English

如何检查DOM元素的标头(h1,h2,h3)属性?

[英]How to check header (h1, h2, h3) property of a DOM element?

如果我对Javascript / jQuery中的链接有引用,如何检查它是否是<h1><h2>等?

使用jQuery.is()方法:

element$.is('h1'); // will return true or false

I assume you mean inside a heading. 我想你说的是标题 You can use :header for that, example: 您可以使用:header ,例如:

<h1><a href="#" id="link">link</a></h1>

var isHeading = !!$('#link').closest(':header').length;

这将为您提供UPPER CASE中元素的标签名称

$('.myClassName').get(0).tagName

You use Jquery.is 您使用Jquery.is

this will check if it is header type (H1,H2,H3...) 这将检查它是否是标题类型(H1,H2,H3 ...)

$('.myClassName').is(':header') 

or 要么

this will check if it is H1 这将检查它是否是H1

$('.myClassName').is('h1')

如果要查找它是否是标题标签:

$(element).is('h1,h2,h3,h4,h5');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改文档中的第一个标头标签( <h2> , <h3> .. <h6> ) 至 <h1> - Change the first header tag in the document (<h2>,<h3>..<h6>) to <h1> 如何自定义 CKEditor 编辑器的 h1、h2、h3、标签格式的外观? - How can I customize the look of the h1,h2,h3, tag format of the CKEditor editor? 如何在javascript中获取所有h1,h2,h3等元素? - How do I get all h1,h2,h3 etc elements in javascript? 如何在javascript中将多个h1元素替换为h1,h2,h3,h4,h5,h6? - How can I do multiple h1 elements replace to h1,h2,h3,h4,h5,h6 in javascript? 如何使用 javascript 在我的富文本编辑器上启用标题(h1、h2、h3、h4)? - How to enable Heading (h1, h2, h3, h4) on my rich text editor using javascript? 如何创建可用作 h1、h2、h3、h4..etc 的 Typography 组件 - How do I create a Typography component that can be used as h1, h2, h3, h4..etc 视差H1和H2 - Parallax H1 and H2 使用我网站上的按钮更改h1 / h2 / h3的字体大小(使用本地存储) - Changing font-size of h1/h2/h3 with button on my website (Using local storage) 使用Jquery在列表中包装多个级别的标头(h1 h2 h3) - Wrapping mulitple levels of headers (h1 h2 h3) in a list using Jquery 如果 Header 通过脚本嵌套在 H2 中,如何将其更改为 H3? - How to change Header to an H3 if it nested inside an H2 through a Script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM