jQuery addClass 或包裹在元素不太可能的部分
我真的很讨厌我的购物车的设置方式,因为我无法编辑大部分页面。所以我求助于使用 jQuery,这既有趣又令人沮丧,因为我们必须使用太多它。话虽这么说..我正在尝试通过 jQuery 找到一种方法来专门针对两种情况的价格添加一个类。不幸的是,价格没有设置为专门为其添加一个类(我无法理解为什么我的购物车会这样做!)。任何帮助将不胜感激!
更新:也许我需要使用wrap()
方法来包装价格并给它一个类?
<-- Situation 1 -->
<b>
<font class="text colors_text">
<b>Regular Price: </b>
</font>
$2,533.31
</b>
<-- Situation 2 -->
<b>
<span class="exclusive">Exclusive Price:</span>
<font class="pricecolor colors_productprice">$2,343.30</font>
</b>
我不会详细解释为什么我需要为这些价格添加一个类,因为类名背后有很多内容,可以使页面的大部分内容正确呈现。每种情况的类名应该相同。情况 2 我可能可以轻松处理 $('.exclusive').next('font').addClass('priceis')
但情况 1 相当困难。
I really hate the way my shopping cart is set up as I CANNOT edit much of the pages. So I resort to using jQuery which is both fun and frustrating because we have to use so much of it. That being said..I am trying to find a way through jQuery to add a class specifically for the price given two situations. Unfortunately the price is not set up to add a class to it specifically (why my shopping cart did it this way is beyond me!). Any help would be appreciated!
UPDATE: Perhaps I need to use wrap()
method to wrap the price and give it a class?
<-- Situation 1 -->
<b>
<font class="text colors_text">
<b>Regular Price: </b>
</font>
$2,533.31
</b>
<-- Situation 2 -->
<b>
<span class="exclusive">Exclusive Price:</span>
<font class="pricecolor colors_productprice">$2,343.30</font>
</b>
I'm not going to dwell into the reasons why I need to add a class to these prices because there is a lot riding behind the class name which enables much of the page to render correctly. The class names for each situation should be the SAME. Situation 2 I may be able to handle with ease $('.exclusive').next('font').addClass('priceis')
but Situation 1 is pretty tough.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于情况一,您可以这样做:
这会在所需类别的价格周围添加一个跨度
For situation one you could do:
this add a span around the price with the desired class