Adding data attribute to DOM

$(‘div’).data(‘info’, 1); alert($(‘div’).data(‘info’)); //this works $(‘div[data-info=”1″]’).text(‘222′); //but this don’t work I’m creating element within jquery. After that, I want to add attribute “data”. He’s like and is added, but in the DOM, this is not apparent, and I can’t get the item, using $(‘div[data-example=”example”]’).html() jsfiddle 6 Answers 6

Whether a variable is undefined [duplicate]

This question already has answers here: How can I check for “undefined” in JavaScript? [duplicate] (16 answers) Closed 2 years ago. How do I find if a variable is undefined? I currently have: var page_name = $(“#pageToEdit :selected”).text(); var table_name = $(“#pageToEdit :selected”).val(); var optionResult = $(“#pageToEditOptions :selected”).val(); var string = “?z=z”; if ( page_name … Read more

Get index of selected option with jQuery

I’m a little bit confused about how to get an index of a selected option from a HTML <select> item. On this page there are two methods described. However, both are always returning -1. Here is my jQuery code: $(document).ready(function(){ $(“#dropDownMenuKategorie”).change(function(){ alert($(“#dropDownMenuKategorie option:selected”).index()); alert($(“select[name=”dropDownMenuKategorie”] option:selected”).index()); }); }); and in html (…) <select id=”dropDownMenuKategorie”> <option value=”gastronomie”>Gastronomie</option> … Read more