使用jQuery替换H3标头中的文本 [英] Using jQuery to replace text inside H3 header

查看:113
本文介绍了使用jQuery替换H3标头中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使代码尽可能简单/干净.两个DIV内部有一个h3.顶部DIV有一个ID,内部DIV有一个唯一的类.

I tried to keep the code as simple/clean as possible. There is an h3 inside of two DIVs. The top DIV has an ID, the inner DIV a unique class.

$("#Events .event-header h3").html("your new header");

我也尝试过:

$("#Events .event-header h3").text("your new header");

均无效.当我在Chrome控制台中尝试使用它们时,它告诉我所引用的元素是未定义的,并且它不知道要定位的文本. DIV的结构再简单不过了.我不知道该如何引用h3标签.

Neither work. When I try them in the Chrome console, it tells me that the element I'm referencing is undefined and it doesn't know what text to target. The DIV structure couldn't be more simple and clear. I don't know how else to reference the h3 tag.

有什么秘诀吗? (我已经修复了.event-header类中的错字-显然,发表评论而不是以前做的是严重的罪过.万圣节快乐?)

Any tips? (I've fixed the typo in the .event-header class - Apparently, posting comments instead of doing that previously is a grave sin. Happy Halloween?)

推荐答案

您的班级是.event-header而不是.events-header

在事件中还有一个额外的"s".

There is an extra "s" at events.

所以试试这个

$("#Events .event-header h3").text("your new header");

小提琴

这篇关于使用jQuery替换H3标头中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆