removeAttr(name) trong jQuery



Miêu tả

Phương thức removeAttr(name) trong jQuery gỡ bỏ một thuộc tính từ mỗi phần tử được so khớp.

Cú pháp

Sau đây là cú pháp cho removeAttr(name) trong jQuery:

selector.removeAttr( name )

Tham số

Dưới đây miêu tả chi tiết về các tham số được sử dụng trong phương thức removeAttr(name) trong jQuery:

  • name − Tên của thuộc tính để bị gỡ bỏ.

Quảng cáo

Ví dụ

Sau đây là ví dụ đơn giản minh họa cách sử dụng của phương thức removeAttr(name) trong jQuery. Ví dụ này sẽ gỡ bỏ border từ mỗi bảng.

<html>
   <head>
      <title>The Selecter Example</title>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
   
      <script type="text/javascript" language="javascript">
         $(document).ready(function() {
            $("table").removeAttr("border");
         });
      </script>
		
   </head>
	
   <body>

      <table border="2">
         <tr><td>This is first table</td></tr>
      </table>

      <table border="3">
         <tr><td>This is second table</td></tr>
      </table>

      <table border="4">
         <tr><td>This is third table</td></tr>
      </table>

   </body>
	
</html>
Quảng cáo

Nó sẽ cho kết quả:

Các bài học jQuery khác tại VietJack:


thuoc_tinh_trong_jquery.jsp