Home > Web Front-end > JS Tutorial > How to select other elements except the last column in jquery

How to select other elements except the last column in jquery

WBOY
Release: 2021-12-01 10:58:41
Original
2655 people have browsed it

In jquery, you can use the "$("Element:not(:last-child)")" statement to select other elements except the last column; the ":last-child" selector can select the last column of elements. , the ":not()" selector is used to select elements other than the specified element.

How to select other elements except the last column in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

How jquery selects elements except the last column

We can use the :last-child selector and the :not(selector) selector to select elements except the last column.

The example is as follows:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $(&#39;tr td:not(:last-child)&#39;).css(&#39;background-color&#39;,&#39;red&#39;);
  });
});
</script>
</head>
<body>
<button>选择除了最后一列的所有元素</button>
<table border="1">
   <tr>
      <td>one</td><td>two</td><td>three</td><td>last</td>
   </tr>
   <tr>
      <td>blue</td><td>red</td><td>green</td><td>last</td>
   </tr>
   <tr>
      <td>Monday</td><td>Tuesday</td><td>Wednesday</td><td>last</td>
   </tr>
</table>
</body>
</html>
Copy after login

Output result:

How to select other elements except the last column in jquery

##After clicking the button:

How to select other elements except the last column in jquery

Recommended related video tutorials:

jQuery video tutorial

The above is the detailed content of How to select other elements except the last column in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template