问题描述
我目前使用的平台不允许我改变已设计的大部分HTML,为了解决这个问题,我需要使用JQuery来查找和替换另一个div的div(或者可能更简单条款(因为我在这里弄错了什么),在HTML中找到文本并用其他文本替换它)。
所以,原文是:
删除类 no-main-image :$('。 ')。removeClass(' 标题降序排序wrapper.has-主图像具有-主图像无主图像') ')addClass(';
..或者您可以使用基本上替换了类:
$('。title-desc-wrapper.has-main-image')。toggleClass('has-main-image no-main-image');
The platform that I'm currently using does not allow me to change much of the HTML that's been designed, so to get around this, I need to use JQuery to find and replace a div with another div (or perhaps in simpler terms (incase I'm getting something wrong here), find text in the HTML and replace it with other text).
So, the original is:
<div class="title-desc-wrapper has-main-image" data-content-field="main-image">I need it to be replaced with:
<div class="title-desc-wrapper no-main-image" data-content-field="main-image">If anyone has any insight into how to do this, or could show me how, I would greatly appreciate it.
解决方案Just add the class has-main-image and remove the class no-main-image:
$('.title-desc-wrapper.has-main-image').removeClass('has-main-image').addClass('no-main-image');..or you could use .toggleClass() to essentially replace the class:
$('.title-desc-wrapper.has-main-image').toggleClass('has-main-image no-main-image');
这篇关于使用jQuery查找并替换元素的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!