jquery selector selector for class not working(boo

2020-05-01 09:22发布

I am using jquery bootpag to display pagination on a page

<div class="textgray showing"></div>

How should I tell jQuery to select this div? I tried the following without but neither of these attempts work

$(".textgray .showing").html("some text");

$(".textgray showing").html("some text");

P.S I am a beginner in frontend so bear with me

2条回答
等我变得足够好
2楼-- · 2020-05-01 09:59

You don't need to put that extra space in between selector. space in selector looks for descendant elements:

$(".textgray.showing").html("some text");
查看更多
小情绪 Triste *
3楼-- · 2020-05-01 10:01

The space means the second part is inside the first one (it's called the descendant combinator). Remove it:

$(".textgray.showing").html("some text");
查看更多
登录 后发表回答