无法选择div内的跨度(jquery)

时间:2022-07-01 21:05:35

I can't seem to select the span inside the image below with the class 'star-rating-control. I'm trying to move it to one of the labels above (which I can select) Can anyone help?

我似乎无法用类'star-rating-control选择下面图像中的跨度。我想把它移到上面的一个标签上(我可以选择)任何人都可以帮忙吗?

无法选择div内的跨度(jquery)

I've tried the following:

我尝试过以下方法:

var test = $("span.star-rating-control");
var test = $("div.write-review form#reviews span.star-rating-control");

If any other information is required, please ask!

如果需要任何其他信息,请询问!

1 个解决方案

#1


You seem to need to use appendTo() method.

您似乎需要使用appendTo()方法。

$("span.star-rating-control").appendTo($("form#reviews label").eq(0));

.eq(0) means "the first element" ( .eq(1) means the second element, etc.).

.eq(0)表示“第一个元素”(.eq(1)表示第二个元素,等等)。

By the way, you should avoid writting div tags inside span tags, into your HTML... Span tags are "inline" elements. Div tags are "block" elements. You can put inline elements inside block elements. But the inverse is not advised according to the W3C.

顺便说一句,你应该避免在span标签内写入div标签到你的HTML ... Span标签是“内联”元素。 Div标签是“块”元素。您可以将内联元素放在块元素中。但根据W3C,不建议采用相反的方法。

#1


You seem to need to use appendTo() method.

您似乎需要使用appendTo()方法。

$("span.star-rating-control").appendTo($("form#reviews label").eq(0));

.eq(0) means "the first element" ( .eq(1) means the second element, etc.).

.eq(0)表示“第一个元素”(.eq(1)表示第二个元素,等等)。

By the way, you should avoid writting div tags inside span tags, into your HTML... Span tags are "inline" elements. Div tags are "block" elements. You can put inline elements inside block elements. But the inverse is not advised according to the W3C.

顺便说一句,你应该避免在span标签内写入div标签到你的HTML ... Span标签是“内联”元素。 Div标签是“块”元素。您可以将内联元素放在块元素中。但根据W3C,不建议采用相反的方法。