html - Pass Text to JavaScript with document.getElementById -


i trying pass text javascript via document.getelementbyid. specifically, trying pass value of id (set "jason_example_12" in example below). can pass values integers, unable pass text.

i have considered using innerhtml, not value, gets between <li> tags.

any appreciated!

thanks!

<script type='text/javascript'>    function ajaxassignfull() { var assignment_string =  var assignment_string = document.getelementbyid('assignment_string_full').value alert(assignment_string);    }  </script>  <li id="assignment_string_full" onclick='ajaxassignfull()' value="jason_example_12"><a  href="#">jason example</a></li> 

value wil make html invalid on li, li not have value attribute. instead try using html5 data-*. can use getattribute('value') discouraged since value invalid on li.

html

<li id="assignment_string_full" onclick='ajaxassignfull()' data-value="jason_example_12"><a  href="#">jason example</a></li> 

script

var assignment_string = document.getelementbyid('assignment_string_full').getattribute('data-value'); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -