{"id":258289,"date":"2024-04-21T07:32:05","date_gmt":"2024-04-21T07:32:05","guid":{"rendered":"https:\/\/namso-gen.co\/blog\/?p=258289"},"modified":"2024-04-21T07:32:05","modified_gmt":"2024-04-21T07:32:05","slug":"how-to-get-selected-li-value-in-javascript","status":"publish","type":"post","link":"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/","title":{"rendered":"How to get selected li value in JavaScript?"},"content":{"rendered":"<p>JavaScript is a powerful programming language that allows you to manipulate HTML elements dynamically. If you&#8217;re working with an unordered list (ul) and want to retrieve the value of the selected list item (li) using JavaScript, there are a few methods you can use. Let&#8217;s explore these methods and find out how you can achieve this.<\/p>\n<p>Before we dive into the solutions, let&#8217;s assume we have the following HTML structure that represents an unordered list:<\/p>\n<p>&#8220;`html<\/p>\n<ul id=\"myList\"><\/p>\n<li value=\"1\">Item 1<\/li>\n<p><\/p>\n<li value=\"2\">Item 2<\/li>\n<p><\/p>\n<li value=\"3\">Item 3<\/li>\n<p>\n<\/ul>\n<p>\n&#8220;`<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_62 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#How_to_get_selected_li_value_in_JavaScript\" title=\"How to get selected li value in JavaScript?\">How to get selected li value in JavaScript?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#Frequently_Asked_Questions\" title=\"Frequently Asked Questions:\">Frequently Asked Questions:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#1_How_can_I_retrieve_the_text_content_of_the_selected_list_item_instead_of_the_value\" title=\"1. How can I retrieve the text content of the selected list item instead of the value?\">1. How can I retrieve the text content of the selected list item instead of the value?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#2_What_if_I_have_multiple_list_items_selected\" title=\"2. What if I have multiple list items selected?\">2. What if I have multiple list items selected?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#3_Can_I_retrieve_the_value_of_the_selected_list_item_without_using_CSS_selectors\" title=\"3. Can I retrieve the value of the selected list item without using CSS selectors?\">3. Can I retrieve the value of the selected list item without using CSS selectors?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#4_How_do_I_handle_cases_where_no_list_item_is_selected\" title=\"4. How do I handle cases where no list item is selected?\">4. How do I handle cases where no list item is selected?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#5_What_if_my_list_items_dont_have_a_value_attribute\" title=\"5. What if my list items don&#8217;t have a value attribute?\">5. What if my list items don&#8217;t have a value attribute?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#6_How_can_I_update_the_selected_list_item_programmatically\" title=\"6. How can I update the selected list item programmatically?\">6. How can I update the selected list item programmatically?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#7_Are_there_alternative_methods_to_retrieve_the_selected_list_item_value\" title=\"7. Are there alternative methods to retrieve the selected list item value?\">7. Are there alternative methods to retrieve the selected list item value?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#8_How_can_I_add_an_event_listener_to_detect_when_the_selected_list_item_changes\" title=\"8. How can I add an event listener to detect when the selected list item changes?\">8. How can I add an event listener to detect when the selected list item changes?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#9_Can_I_get_the_selected_list_item_value_without_using_the_id_of_the_list\" title=\"9. Can I get the selected list item value without using the id of the list?\">9. Can I get the selected list item value without using the id of the list?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#10_What_if_my_list_items_are_dynamically_added_or_removed\" title=\"10. What if my list items are dynamically added or removed?\">10. What if my list items are dynamically added or removed?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#11_Can_I_use_this_method_with_other_types_of_lists_like_ordered_lists_ol\" title=\"11. Can I use this method with other types of lists, like ordered lists (ol)?\">11. Can I use this method with other types of lists, like ordered lists (ol)?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#12_Is_this_method_supported_in_all_browsers\" title=\"12. Is this method supported in all browsers?\">12. Is this method supported in all browsers?<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"How_to_get_selected_li_value_in_JavaScript\"><\/span>How to get selected li value in JavaScript?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p><strong>The simplest way to retrieve the value of a selected list item in JavaScript is by using the <code>querySelector<\/code> method combined with CSS selectors.<\/strong> This method allows you to select elements from the DOM using a CSS selector syntax. In our case, we can use the <code>:checked<\/code> pseudo-class to target the selected list item.<\/p>\n<p><\/p>\n<p>Here&#8217;s an example of how you can accomplish this:<\/p>\n<p>&#8220;`javascript<br \/>\nconst selectedValue = document.querySelector(&#8220;#myList li:checked&#8221;).value;<br \/>\nconsole.log(selectedValue);<br \/>\n&#8220;`<\/p>\n<p>In the above example, the <code>querySelector<\/code> method targets the first <code>li<\/code> element that is both a child of the element with the id &#8220;myList&#8221; and is checked. The <code>.value<\/code> property retrieves the value attribute of the selected list item, which can be accessed or stored as needed.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h3><span class=\"ez-toc-section\" id=\"1_How_can_I_retrieve_the_text_content_of_the_selected_list_item_instead_of_the_value\"><\/span>1. How can I retrieve the text content of the selected list item instead of the value?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>To retrieve the text content of the selected list item, you can replace the <code>.value<\/code> property with the <code>.textContent<\/code> property. For example:<\/p>\n<p>&#8220;`javascript<br \/>\nconst selectedText = document.querySelector(&#8220;#myList li:checked&#8221;).textContent;<br \/>\nconsole.log(selectedText);<br \/>\n&#8220;`<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_What_if_I_have_multiple_list_items_selected\"><\/span>2. What if I have multiple list items selected?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>If you have multiple list items selected, you can use the <code>querySelectorAll<\/code> method instead of <code>querySelector<\/code>. This method returns a collection of selected list items that you can iterate over to retrieve their values. Here&#8217;s an example:<\/p>\n<p>&#8220;`javascript<br \/>\nconst selectedItems = document.querySelectorAll(&#8220;#myList li:checked&#8221;);<br \/>\nselectedItems.forEach(item => console.log(item.value));<br \/>\n&#8220;`<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Can_I_retrieve_the_value_of_the_selected_list_item_without_using_CSS_selectors\"><\/span>3. Can I retrieve the value of the selected list item without using CSS selectors?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>Yes, you can also achieve this by iterating over all list items and checking their <code>checked<\/code> property. Here&#8217;s an example:<\/p>\n<p>&#8220;`javascript<br \/>\nconst listItems = document.querySelectorAll(&#8220;#myList li&#8221;);<br \/>\nlistItems.forEach(item => {<br \/>\n  if (item.checked) {<br \/>\n    console.log(item.value);<br \/>\n    \/\/ or console.log(item.textContent) for text content<br \/>\n  }<br \/>\n});<br \/>\n&#8220;`<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_How_do_I_handle_cases_where_no_list_item_is_selected\"><\/span>4. How do I handle cases where no list item is selected?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>You can handle the case where no list item is selected by checking if the returned value is null or undefined. For example:<\/p>\n<p>&#8220;`javascript<br \/>\nconst selectedValue = document.querySelector(&#8220;#myList li:checked&#8221;);<br \/>\nif (selectedValue) {<br \/>\n  console.log(selectedValue.value);<br \/>\n} else {<br \/>\n  console.log(&#8220;No list item selected.&#8221;);<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h3><span class=\"ez-toc-section\" id=\"5_What_if_my_list_items_dont_have_a_value_attribute\"><\/span>5. What if my list items don&#8217;t have a value attribute?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>If your list items don&#8217;t have a value attribute, you can use the <code>.innerText<\/code> property instead of <code>.value<\/code> or <code>.textContent<\/code> to retrieve their displayed text. Here&#8217;s an example:<\/p>\n<p>&#8220;`javascript<br \/>\nconst selectedText = document.querySelector(&#8220;#myList li:checked&#8221;).innerText;<br \/>\nconsole.log(selectedText);<br \/>\n&#8220;`<\/p>\n<h3><span class=\"ez-toc-section\" id=\"6_How_can_I_update_the_selected_list_item_programmatically\"><\/span>6. How can I update the selected list item programmatically?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>To programmatically update the selected list item, you can use the <code>checked<\/code> property to set it to true or false. Here&#8217;s an example:<\/p>\n<p>&#8220;`javascript<br \/>\nconst listItem = document.querySelector(&#8220;#myList li&#8221;); \/\/ Select any list item<br \/>\nlistItem.checked = true; \/\/ or false to deselect<br \/>\n&#8220;`<\/p>\n<h3><span class=\"ez-toc-section\" id=\"7_Are_there_alternative_methods_to_retrieve_the_selected_list_item_value\"><\/span>7. Are there alternative methods to retrieve the selected list item value?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>Yes, you can also use frameworks or libraries like jQuery to simplify the selection and retrieval of the selected list item value. jQuery provides a convenient <code>:checked<\/code> selector that you can use. Here&#8217;s an example:<\/p>\n<p>&#8220;`javascript<br \/>\nconst selectedValue = $(&#8220;#myList li:checked&#8221;).val();<br \/>\nconsole.log(selectedValue);<br \/>\n&#8220;`<\/p>\n<h3><span class=\"ez-toc-section\" id=\"8_How_can_I_add_an_event_listener_to_detect_when_the_selected_list_item_changes\"><\/span>8. How can I add an event listener to detect when the selected list item changes?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>You can add an event listener to the list items&#8217; parent element, such as the unordered list, to detect changes in the selected item. Here&#8217;s an example using the <code>addEventListener<\/code> method:<\/p>\n<p>&#8220;`javascript<br \/>\nconst list = document.querySelector(&#8220;#myList&#8221;);<br \/>\nlist.addEventListener(&#8220;change&#8221;, function() {<br \/>\n  const selectedValue = document.querySelector(&#8220;#myList li:checked&#8221;).value;<br \/>\n  console.log(selectedValue);<br \/>\n});<br \/>\n&#8220;`<\/p>\n<h3><span class=\"ez-toc-section\" id=\"9_Can_I_get_the_selected_list_item_value_without_using_the_id_of_the_list\"><\/span>9. Can I get the selected list item value without using the id of the list?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>Yes, you can use other attributes, classes, or selectors to target the unordered list and retrieve the selected list item value. Here&#8217;s an example using the class attribute:<\/p>\n<p>&#8220;`javascript<br \/>\nconst selectedValue = document.querySelector(&#8220;.myListClass li:checked&#8221;).value;<br \/>\nconsole.log(selectedValue);<br \/>\n&#8220;`<\/p>\n<h3><span class=\"ez-toc-section\" id=\"10_What_if_my_list_items_are_dynamically_added_or_removed\"><\/span>10. What if my list items are dynamically added or removed?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>If your list items are dynamically added or removed, you may need to reevaluate the selected list item value whenever changes occur. You can achieve this by wrapping the code that retrieves the selected value within a function and calling it whenever needed.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"11_Can_I_use_this_method_with_other_types_of_lists_like_ordered_lists_ol\"><\/span>11. Can I use this method with other types of lists, like ordered lists (ol)?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>Yes, you can apply the same method to ordered lists (ol) as well. Just make sure to adjust the selector to match the appropriate HTML structure.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"12_Is_this_method_supported_in_all_browsers\"><\/span>12. Is this method supported in all browsers?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><\/p>\n<p>Yes, the method shown here is widely supported in all modern browsers, including Chrome, Firefox, Safari, and Edge. However, for older versions of Internet Explorer, you may need to use alternative methods or polyfills.<\/p>\n<p>Now that you know how to retrieve the selected list item value in JavaScript, you can confidently incorporate this functionality into your projects. Whether you&#8217;re building a form or creating dynamic content, manipulating DOM elements using JavaScript opens up endless possibilities.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript is a powerful programming language that allows you to manipulate HTML elements dynamically. If you&#8217;re working with an unordered list (ul) and want to retrieve the value of the selected list item (li) using JavaScript, there are a few methods you can use. Let&#8217;s explore these methods and find out how you can achieve &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to get selected li value in JavaScript?\" class=\"read-more button\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#more-258289\">Read more<span class=\"screen-reader-text\">How to get selected li value in JavaScript?<\/span><\/a><\/p>\n","protected":false},"author":65,"featured_media":107420,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86279],"tags":[],"class_list":["post-258289","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn","no-featured-image-padding"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to get selected li value in JavaScript?<\/title>\n<meta name=\"description\" content=\"JavaScript is a powerful programming language that allows you to manipulate HTML elements dynamically. If you&#039;re working with an unordered list (ul) and\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to get selected li value in JavaScript?\" \/>\n<meta property=\"og:description\" content=\"JavaScript is a powerful programming language that allows you to manipulate HTML elements dynamically. If you&#039;re working with an unordered list (ul) and\" \/>\n<meta property=\"og:url\" content=\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/synchronyfinancial\" \/>\n<meta property=\"article:published_time\" content=\"2024-04-21T07:32:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2024\/03\/faq.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Timothy Mathis\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@synchrony\" \/>\n<meta name=\"twitter:site\" content=\"@synchrony\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Timothy Mathis\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/\"},\"author\":{\"name\":\"Timothy Mathis\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318\"},\"headline\":\"How to get selected li value in JavaScript?\",\"datePublished\":\"2024-04-21T07:32:05+00:00\",\"dateModified\":\"2024-04-21T07:32:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/\"},\"wordCount\":881,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"articleSection\":[\"Learn\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/\",\"name\":\"How to get selected li value in JavaScript?\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\"},\"datePublished\":\"2024-04-21T07:32:05+00:00\",\"dateModified\":\"2024-04-21T07:32:05+00:00\",\"description\":\"JavaScript is a powerful programming language that allows you to manipulate HTML elements dynamically. If you're working with an unordered list (ul) and\",\"breadcrumb\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/namso-gen.co\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to get selected li value in JavaScript?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"description\":\"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co\",\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/namso-gen.co\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"contentUrl\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"width\":500,\"height\":164,\"caption\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\"},\"image\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/synchronyfinancial\",\"https:\/\/twitter.com\/synchrony\",\"https:\/\/www.youtube.com\/synchronyfinancial\",\"https:\/\/www.instagram.com\/synchrony\",\"https:\/\/www.linkedin.com\/company\/synchrony-financial\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318\",\"name\":\"Timothy Mathis\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"Timothy Mathis\"},\"description\":\"Guest author Timothy Mathis has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to get selected li value in JavaScript?","description":"JavaScript is a powerful programming language that allows you to manipulate HTML elements dynamically. If you're working with an unordered list (ul) and","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to get selected li value in JavaScript?","og_description":"JavaScript is a powerful programming language that allows you to manipulate HTML elements dynamically. If you're working with an unordered list (ul) and","og_url":"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/","og_site_name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","article_publisher":"https:\/\/www.facebook.com\/synchronyfinancial","article_published_time":"2024-04-21T07:32:05+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2024\/03\/faq.png","type":"image\/png"}],"author":"Timothy Mathis","twitter_card":"summary_large_image","twitter_creator":"@synchrony","twitter_site":"@synchrony","twitter_misc":{"Written by":"Timothy Mathis","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#article","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/"},"author":{"name":"Timothy Mathis","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318"},"headline":"How to get selected li value in JavaScript?","datePublished":"2024-04-21T07:32:05+00:00","dateModified":"2024-04-21T07:32:05+00:00","mainEntityOfPage":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/"},"wordCount":881,"commentCount":0,"publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"articleSection":["Learn"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/","url":"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/","name":"How to get selected li value in JavaScript?","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/#website"},"datePublished":"2024-04-21T07:32:05+00:00","dateModified":"2024-04-21T07:32:05+00:00","description":"JavaScript is a powerful programming language that allows you to manipulate HTML elements dynamically. If you're working with an unordered list (ul) and","breadcrumb":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/namso-gen.co\/blog\/how-to-get-selected-li-value-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/namso-gen.co\/blog\/"},{"@type":"ListItem","position":2,"name":"How to get selected li value in JavaScript?"}]},{"@type":"WebSite","@id":"https:\/\/namso-gen.co\/blog\/#website","url":"https:\/\/namso-gen.co\/blog\/","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","description":"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co","publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/namso-gen.co\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/namso-gen.co\/blog\/#organization","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","url":"https:\/\/namso-gen.co\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","contentUrl":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","width":500,"height":164,"caption":"Namso Gen Blog - Free Credit Card Generator [100% Valid]"},"image":{"@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/synchronyfinancial","https:\/\/twitter.com\/synchrony","https:\/\/www.youtube.com\/synchronyfinancial","https:\/\/www.instagram.com\/synchrony","https:\/\/www.linkedin.com\/company\/synchrony-financial"]},{"@type":"Person","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318","name":"Timothy Mathis","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"Timothy Mathis"},"description":"Guest author Timothy Mathis has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here."}]}},"_links":{"self":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/258289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/comments?post=258289"}],"version-history":[{"count":0,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/258289\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media\/107420"}],"wp:attachment":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media?parent=258289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/categories?post=258289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/tags?post=258289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}