JQuery - 如果存在某些其他元素,则将某些元素类更改为特定类 [英] JQuery - Change certain element classes to specific classes if certain other element is present

查看:71
本文介绍了JQuery - 如果存在某些其他元素,则将某些元素类更改为特定类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试编写一个博客主题,其中包含标签等,因此我希望看到某些类型的大多数父级div在标记某些内容时更改(例如下面的内容)。

Hi there I'm trying to code a blog theme which will have tags etc so wat I'd like is for certain classes of mostly parent divs to change when tagged with something (example below).

类是跨度(使用bootstrap)

classes are spans (using bootstrap)

html

<div id="a" class="span6">
</div>

<div id="b" class="span6">

<a class="taglink">[tag]</a>

</div>

我想要的是将div a和b的类更改为span12和只有他们,没有其他父/邻居/子等等div。

What I'd like is for div a and b's classes to change to say span12, and only them and no other parent/adjacent/child etc divs.

这是当我用某些标签标记帖子时我想要的一些要更改的布局属性(通过其css类)

This is so that when I tag the post with certain tags I'd like some of its layout properties to change (via its css class)

推荐答案

为a.taglink的内容创建事件监听器更改,然后使用以下内容:

Create an event listener for when the content of the a.taglink changes, then use the following:

$('#a.span6,#b.span6').removeClass('span6').addClass('span12');

这篇关于JQuery - 如果存在某些其他元素,则将某些元素类更改为特定类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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