how to get data value from html in javascript function?

Ashley Shen

Hi I'm a beginner of jquery and ajax. This is my code:

.html

<li class="list-group-item">        
    <h2>Vocabulary</h2>
    <h4>
      <span class="label label-success">Like Name</span>  
      <span class="label label-danger">GEPT</span>
      <button type="button" id="collapsible" class="btn btn-default" data-toggle="collapse" data-target="#intro" data-word="good" onclick="loadXMLDoc()">
        <span class="glyphicon glyphicon-plus"></span>
      </button>
    </h4>
    <div class="collapse" id="intro">
      <div class="detail">
        <img src='http://www.michigan.com/assets/images/loading-module.gif'/>
      </div>         
    </div>
  </li>
  <li class="list-group-item">    

javascript:

function loadXMLDoc()
{
  var xmlhttp;
  var word = $(this).data("word");
  var path='get_word_detail.php?word='+word;
  if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }else{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
    document.getElementById("intro").innerHTML=xmlhttp.responseText;
  }
}
xmlhttp.open("GET",path,true);
xmlhttp.send();

}

My page contain a list with many collapsed list items. Every list item containing a button to expand the content of the item.

i want to get the "data-word" from html but it didnt work, Do anyone know how to do it correctly and whether it's possible for me to just pass the parameter from html tag like "onclick="loadXMLDoc("good")"?

Thanks

Anoop Joshi

use attr function of jquery

$("#collapsible").attr("data-word");

EDIT

$(".btn").click(function(){
alert($(this).attr("data-word"));
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get an HTML value using a JavaScript function

From Dev

How to get value from specific cell from a HTML table with JavaScript

From Dev

How do I return a value from a function in JavaScript to a textbox in HTML

From Dev

How do I return a value from a function in JavaScript to a textbox in HTML

From Dev

how to get the value of a function from a button click in javascript?

From Dev

How to get a value from function javascript and print it to the chart

From Dev

Javascript: How to get the value of a function?

From Dev

How to get a key/value data set from a HTML form

From Dev

How to get value from nested HTML tag with Jquery/Javascript

From Dev

Javascript - how to get a float value from an HTML input?

From Dev

how to get the smallest value in javascript by getting data from DOM

From Dev

How to get a data from a value with 2 or more items in javascript

From Dev

How to get rid of html tags and javascript functions from the scraped data?

From Dev

How to get javascript var data from html element? (working with canvasjs)

From Dev

How to get javascript var data from html element? (working with canvasjs)

From Dev

How to get a value from function?

From Dev

how to get a value from function

From Dev

How I can call javascript function and get the return value from javascript function

From Dev

How to get data from HTML?

From Dev

Get return value from async function in Javascript

From Dev

Get value from a javascript function in a php variable

From Dev

Get ajax value from JavaScript function

From Dev

Get value from a javascript function in a php variable

From Dev

Get value from html textbox with javascript

From Dev

Get a Specific Value from Serialized Data in Javascript

From Dev

Pass the value attribute data from HTML side to JavaScript function via onclick event

From Dev

R get html data from a javascript action

From Dev

How to print or get the cell value from HTML TABLE(User Input) in html and javascript

From Dev

How to print or get the cell value from HTML TABLE(User Input) in html and javascript

Related Related

  1. 1

    How to get an HTML value using a JavaScript function

  2. 2

    How to get value from specific cell from a HTML table with JavaScript

  3. 3

    How do I return a value from a function in JavaScript to a textbox in HTML

  4. 4

    How do I return a value from a function in JavaScript to a textbox in HTML

  5. 5

    how to get the value of a function from a button click in javascript?

  6. 6

    How to get a value from function javascript and print it to the chart

  7. 7

    Javascript: How to get the value of a function?

  8. 8

    How to get a key/value data set from a HTML form

  9. 9

    How to get value from nested HTML tag with Jquery/Javascript

  10. 10

    Javascript - how to get a float value from an HTML input?

  11. 11

    how to get the smallest value in javascript by getting data from DOM

  12. 12

    How to get a data from a value with 2 or more items in javascript

  13. 13

    How to get rid of html tags and javascript functions from the scraped data?

  14. 14

    How to get javascript var data from html element? (working with canvasjs)

  15. 15

    How to get javascript var data from html element? (working with canvasjs)

  16. 16

    How to get a value from function?

  17. 17

    how to get a value from function

  18. 18

    How I can call javascript function and get the return value from javascript function

  19. 19

    How to get data from HTML?

  20. 20

    Get return value from async function in Javascript

  21. 21

    Get value from a javascript function in a php variable

  22. 22

    Get ajax value from JavaScript function

  23. 23

    Get value from a javascript function in a php variable

  24. 24

    Get value from html textbox with javascript

  25. 25

    Get a Specific Value from Serialized Data in Javascript

  26. 26

    Pass the value attribute data from HTML side to JavaScript function via onclick event

  27. 27

    R get html data from a javascript action

  28. 28

    How to print or get the cell value from HTML TABLE(User Input) in html and javascript

  29. 29

    How to print or get the cell value from HTML TABLE(User Input) in html and javascript

HotTag

Archive