Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

jQuery - Miscellaneous Methods

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  personObj = new Object();
  personObj.firstname = "John";
  personObj.lastname = "Doe";
  personObj.age = 50;
  personObj.eyecolor = "blue";
  
  $("#btndataAtt").click(function(){
    $("#div21").data("greeting", "Hello World");
  });
  $("#btndataGet").click(function(){
    $("#div21").text($("#div21").data("greeting"));
  });
  $("#btnremoveData").click(function(){
    $("#div21").removeData("greeting");
    $("#div21").text($("#div21").data("greeting"));
  });
  
  $("#btndataAtt2").click(function(){
    $("#div22").data(personObj);
  });
  $("#btndataGet2").click(function(){
    $("#div22").text($("#div22").data("firstname"));
  });
  
  $("#btnParam").click(function(){
    $("#div1").text($.param(personObj));
  });
});
</script>
</head>
<body>

<hr>
<a href="https://www.w3schools.com/jquery/jquery_ref_misc.asp"><h2>jQuery Misc Methods</h2></a>
<table class="w3-table-all notranslate" border="1">
<tr>
<th style="width:20%">Method</th>
<th>Description</th>
</tr>
<tr>
<td><a>data()</a></td>
<td>Attaches data to, or gets data from, selected elements</td>
</tr>
<tr>
<td><a href="misc_each.asp">each()</a></td>
<td>Execute a function for each matched element</td>
</tr>
<tr>
<td><a href="misc_get.asp">get()</a></td>
<td>Get the DOM elements matched by the selector</td>
</tr>
<tr>
<td><a href="misc_index.asp">index()</a></td>
<td>Search for a given element from among the matched elements</td>
</tr>
<tr>
<td><a href="misc_noconflict.asp">$.noConflict()</a></td>
<td>Release jQuery's control of the $ variable</td>
</tr>
<tr>
<td><a>$.param()</a></td>
<td>Create a serialized representation of an array or object (can be used as URL query string 
for AJAX requests)</td>
</tr>
<tr>
<td><a>removeData()</a></td>
<td>Removes a previously-stored piece of data</td>
</tr>
  <tr>
<td><a>size()</a></td>
<td><span class="deprecated">Removed in version 3.0.</span> Use the <a href="prop_length.asp">length</a> 
property instead</td>
  </tr>
  <tr>
<td><a href="misc_toarray.asp">toArray()</a></td>
<td>Retrieve all the DOM elements contained in the jQuery set, as an array</td>
  </tr>
</table>

<h3>$.param() Method</h3>
<table border="1">
  <tr>
    <td>
      <button id="btnParam">$.param()</button>
    </td>
    <td width="100px">
    <div id="div1"></div>    
    </td>
  </tr>
</table>

<h3>jQuery Misc data() Method</h3>
<table border="1">
  <tr>
    <td>
      <button id="btndataAtt">Attach data</button>
      <br>
      <button id="btndataGet">Get data</button>
      <br>
      <button id="btnremoveData">Remove data</button>
    </td>
    <td width="100px">
    <div id="div21"></div>    
    </td>
  </tr>
  <tr>
    <td>
      <button id="btndataAtt2">Attach data to div element(Oject)</button>
      <br>
      <button id="btndataGet2">Get data attached to div element(Oject)</button>      
    </td>
    <td width="100px">
    <div id="div22"></div>    
    </td>
  </tr>  
</table>


</body>
</html>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.