简体   繁体   English

Javascript - 在DIV中选择H1

[英]Javascript - Select H1 inside DIV

I've searched all I can about this and found answers that are seemingly correct. 我尽我所能搜索了这个,并找到了看似正确的答案。 But it doesn't work for me. 但它对我不起作用。 I have this CKEditor inside a div. 我在div里面有这个CKEditor。 Inside this CKEditor, there are lots of content and I want to add a hover event on all H1 styles inside this editor. 在这个CKEditor中,有很多内容,我想在这个编辑器中的所有H1样式上添加一个悬停事件。

The div structure looks like this: div结构如下所示:

<div id="content" class="cke_editable">
   <h1>
      <span>My content</span>
    </h1>
</div>

I'm trying to use qTip2 actually, since it seems to fit my needs. 我正在尝试使用qTip2,因为它似乎符合我的需求。 But I can't manage to select the H1 tag. 但我无法选择H1标签。 Is it because it's inside a div which has both an ID and a class? 是因为它在一个既有ID又有类的div中? Or does it have anything to do with the fact that there's a <span> tag inside the H1? 或者它与H1内部的<span>标签有什么关系?

Here's the javascript: 这是javascript:

<script type="text/javascript">
var shared = {
    position: {
        my: 'top left', 
        at: 'bottom right',
    },
    style: {
        tip: true
    }
};

$('h1').qtip( $.extend({}, shared, { 
    content: 'An example tooltip',
    style: {
        classes: 'ui-tooltip-red'
    }
}));
</script>

When it comes to the selector, I've tried selecting only H1, like in this example. 当谈到选择器时,我尝试只选择H1,就像在这个例子中一样。 As well as $('.cke_editable h1') , $('#content h1') and $('#content > h1') . 以及$('.cke_editable h1')$('#content h1')$('#content > h1') But no dice. 但没有骰子。 In my CSS, I've successfully added cursor: pointer to #content h1 . 在我的CSS中,我已成功添加了cursor: pointer #content h1 cursor: pointer And that works. 这很有效。

Am I doing something wrong here? 我在这里做错了吗?

Edit: If I select $('#content').qtip directly, it works btw. 编辑:如果我选择$('#content').qtip直接,它的工作顺便说一句。

Try to put it like this: 试着这样说:

$('h1','#content').qtip

or: 要么:

$('#content').find('h1').qtip

CKEditor在它放置内容时创建一个iframe,因此您不能使用jQuery选择器来选择其中的元素,因为它甚至不再在同一个文档中。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM