简体   繁体   English

我如何使用 jquery 在 html 中取值并从其他值中扣除

[英]How can i take value and deduct it from other in html using jquery

I want jquery for taking value from `<td>` and will deduct it from h2 tag in final output place.This is the for loop exact area.
           <% photolist.forEach(function(photo){ %>  
    <tr>                        
         <td id="likescount"><%=photo.likes_count%></td>
      </tr>
     <%})%>

I want to access this count from array to substract.我想从数组中访问这个计数以进行减法。

No need for jQuery无需 jQuery

const h2 = document.querySelector(".totallikes");
h2.textContent -= document.getElementById("likescount").textContent; 

NOTE : The minus casts to number注意:减号转换为数字

 const h2 = document.querySelector(".totallikes"); h2.textContent -= document.getElementById("likescount").textContent;
 <div class="col-lg-3"> <div class="widget style1 lazur-bg"> <div class="row"> <div class="col-4"> <i class="fa fa-thumbs-o-up fa-5x"></i> </div> <div class="col-8 text-right"> <span>Total no. of likes </span> <h2 class="totallikes font-bold">45</h2> </div> </div> </div> </div> <table> <tbody> <tr> <td id="likescount">5</td> </tr> </tbody> </table>

If it MUST be jQuery then如果它必须是 jQuery 那么

const $h2 = $(".totallikes");
$h2.text($h2.text() - $("#likescount").text())

 const $h2 = $(".totallikes"); $h2.text($h2.text() - $("#likescount").text())
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="col-lg-3"> <div class="widget style1 lazur-bg"> <div class="row"> <div class="col-4"> <i class="fa fa-thumbs-o-up fa-5x"></i> </div> <div class="col-8 text-right"> <span>Total no. of likes </span> <h2 class="totallikes font-bold">45</h2> </div> </div> </div> </div> <table> <tbody> <tr> <td id="likescount">5</td> </tr> </tbody> </table>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从数字中扣除一个百分比,然后使用Javascript或Jquery将差异分配给innerHTML属性? - How do i deduct a percentage from a number and assign the difference to the innerHTML attribute using Javascript or Jquery? 如何仅在 HTML/JQuery 中获取从 1 到 10 的输入? - How can I take input from 1 to 10 only in HTML/JQuery? 如何从 vue 中的跨度 html 中获取值? - How can I take a value from a span html in vue? 我如何使用 html2canvas 截取 HTML 的屏幕截图,Javascript 中的其他库 - How can i take Screenshot of HTML using html2canvas, Other Lib in Javascript 如何使用 jQuery 从字符串中删除输入标签? 该字符串还包含其他 html 标签 - How can I remove input tags from a string using jQuery? This string contains other html tags as well 如何从PHP的jquery mobile开关滑块中提取值 - How can i take out value from jquery mobile on and off slider in PHP 带有jQuery的动态文本框如何从Servlet动态获取值 - Dynamic textbox with jquery how can I take the value dynamically from the servlet 为什么我无法访问html元素的属性值之一,但是我可以使用jQuery访问其他值? - Why i can't access one of the html element's attribute value, but i can access other ones using jQuery? 如何从 javascript 中的运行计时器中扣除 10 秒? - How can you deduct 10 seconds from a running timer in javascript? 我如何使用 jQuery 删除除特定 class 之外的所有 div 和其他 DOM HTML 元素 - How can i remove all div's and other DOM HTML elements except a particular class using jQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM