{"id":43919,"date":"2019-03-07T03:01:13","date_gmt":"2019-03-06T17:01:13","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=43919"},"modified":"2024-01-11T07:23:12","modified_gmt":"2024-01-10T21:23:12","slug":"htmlcssjavascript-pulldown-menus-javascript-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/htmlcssjavascript-pulldown-menus-javascript-tutorial\/","title":{"rendered":"HTML\/CSS\/Javascript Pulldown Menus Javascript Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/PulldownMenus\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"HTML\/CSS\/Javascript Pulldown Menus Javascript Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/PulldownMenus\/Pulldown_Menus_qsall.jpg\" title=\"HTML\/CSS\/Javascript Pulldown Menus Javascript Tutorial\" \/><\/a><p class=\"wp-caption-text\">HTML\/CSS\/Javascript Pulldown Menus Javascript Tutorial<\/p><\/div>\n<p>When we last discussed pulldown menus with <a title='HTML\/CSS\/Javascript Pulldown Menus Primer Tutorial' href='#html\/css\/jpmpt'>HTML\/CSS\/Javascript Pulldown Menus Primer Tutorial<\/a> we didn&#8217;t involve any blocks of Javascript code in the document.head section of the webpage, and no document.body onload event logic.   As of today, that is not the case, because we are using the Javascript and document.body onload event call below &#8230;<\/p>\n<p><code><br \/>\n<b>&lt;script type='text\/javascript'&gt;<br \/>\nvar sp1=null;<br \/>\nfunction onl() { \/\/ thanks to <a target=_blank title='Useful link' href='https:\/\/coursesweb.net\/javascript\/queryselector-queryselectorall'>https:\/\/coursesweb.net\/javascript\/queryselector-queryselectorall<\/a><br \/>\nvar gp='https:\/\/www.google.com\/search?q='; \/\/ Mount+Kenya&rlz=1C5CHFA_enAU832AU832&oq='; \/\/Mount+Kenya<br \/>\nif (sp1 == null) { sp1 = document.getElementById('more'); }<br \/>\n<br \/>\n\/\/ gets A tags added in document.body<br \/>\nvar xelms = document.body.querySelectorAll('a');<br \/>\n<br \/>\n\/\/registers mouseenter to each element in xelms array<br \/>\nfor(var xi=0; xi&lt;xelms.length; xi++){<br \/>\n xelms[xi].addEventListener('mouseenter', (ev)=&gt;{<br \/>\n if (ev.target.href.substring(0,1) != '#' && ev.target.href.indexOf(document.URL + '#') == -1) {<br \/>\n   if (ev.target.innerHTML.indexOf(' (') != -1) {<br \/>\n   sp1.innerHTML = '&lt;a style=\"text-decoration:underline;cursor:pointer;\" target=_blank title=\"Google search for ' + ev.target.innerHTML + '\" href=\"' + gp + ev.target.innerHTML.split(' (')[0].replace(\/\\ \/g,'+') + '+mountain' + '\"&gt;' + ev.target.innerHTML + '&lt;\/a&gt;';<br \/>\n   } else {<br \/>\n   sp1.innerHTML = ev.target.href;<br \/>\n   }<br \/>\n } else if (ev.target.outerHTML.split('&gt;')[0].indexOf('http') != -1) {<br \/>\n   sp1.innerHTML = '&lt;a style=\"text-decoration:underline;cursor:pointer;\" target=_blank title=\"Wikipedia page for highest mountains in ' + ev.target.innerHTML + '\" href=\"http' + ev.target.outerHTML.split('&gt;')[0].split('http')[1].split(\"'\")[0].split('\"')[0] + '\"&gt; in ' + ev.target.innerHTML + '&lt;\/a&gt;';<br \/>\n }<br \/>\n });<br \/>\n}<br \/>\n<br \/>\n\/\/ gets A tags in LI in UL added in element with id='topdiv'<br \/>\nvar elms = document.getElementById('topdiv').querySelectorAll('ul li a');<br \/>\n<br \/>\n\/\/registers mouseenter to each element in elms array<br \/>\nfor(var i=0; i&lt;elms.length; i++){<br \/>\n elms[i].addEventListener('mouseenter', (ev)=&gt;{<br \/>\n if (ev.target.href.substring(0,1) != '#' && ev.target.href.indexOf(document.URL + '#') == -1) {<br \/>\n   if (ev.target.innerHTML.indexOf(' (') != -1) {<br \/>\n   sp1.innerHTML = '&lt;a style=\"text-decoration:underline;cursor:pointer;\" target=_blank title=\"Google search for ' + ev.target.innerHTML + '\" href=\"' + gp + ev.target.innerHTML.split(' (')[0].replace(\/\\ \/g,'+') + '+mountain' + '\"&gt;' + ev.target.innerHTML + '&lt;\/a&gt;';<br \/>\n   } else {<br \/>\n   sp1.innerHTML = ev.target.href;<br \/>\n   }<br \/>\n } else if (ev.target.outerHTML.split('&gt;')[0].indexOf('http') != -1) {<br \/>\n   sp1.innerHTML = '&lt;a style=\"text-decoration:underline;cursor:pointer;\" target=_blank title=\"Wikipedia page for highest mountains in ' + ev.target.innerHTML + '\" href=\"http' + ev.target.outerHTML.split('&gt;')[0].split('http')[1].split(\"'\")[0].split('\"')[0] + '\"&gt; in ' + ev.target.innerHTML + '&lt;\/a&gt;';<br \/>\n }<br \/>\n });<br \/>\n}<br \/>\n}<br \/>\n&lt;\/script&gt;<\/b><br \/>\n<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body<b> onload=\"onl();\"<\/b> title=\"Mt Everest (8848 m) is Highest Mountain in the World ... but this is Blue Mountains in NSW, Australia\"&gt;<br \/>\n<\/code><\/p>\n<p>The central &#8220;plank&#8221; to this new Javasacript logic is the use of Javascript DOM <a target=_blank title='HTML DOM querySelectorAll() Method information from w3schools' href='https:\/\/www.w3schools.com\/jsref\/met_document_queryselectorall.asp'>querySelectorAll<\/a>() followup, if you will, to the <a target=_blank title='HTML DOM querySelector() Method information from w3schools' href='https:\/\/www.w3schools.com\/jsref\/met_document_queryselector.asp'>querySelector<\/a>() deployed when we changed the Tic Tac Toe game, last, when we presented <a target=_blank title='Tic Tac Toe Class Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/tic-tac-toe-class-tutorial\/'>Tic Tac Toe Class Tutorial<\/a>, the &#8220;All&#8221; difference being that all HTML elements found for a criteria scope of code can be &#8220;visited&#8221; (or transited) as the querySelectorAll arrangements are made at the document.body onload event logic as above.<\/p>\n<p>This type of Javascript code shows a meeting of DOM (action) and CSS (styling) &#8220;minds&#8221;, to our mind.<\/p>\n<p>You can try this pulldown menus web application for yourself at this <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/PulldownMenus\/\">live run<\/a> link and\/or peruse <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/PulldownMenus\/pulldown_menus.html-GETME\" title=\"pulldown_menus.html\">the changed<\/a> HTML and CSS and Javascript pulldown menus <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/PulldownMenus\/pulldown_menus.html-GETME\" title=\"pulldown_menus.html\">pulldown_menus.html<\/a> code whereby new linking to information dynamically appears within the topmost HTML h1 element.<\/p>\n<hr>\n<p id='html\/css\/jpmpt'>Previous relevant <a target=_blank title='HTML\/CSS\/Javascript Pulldown Menus Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/html\/css\/javascript-pulldown-menus-primer-tutorial\/'>HTML\/CSS\/Javascript Pulldown Menus Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/PulldownMenus\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"HTML\/CSS\/Javascript Pulldown Menus Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/PulldownMenus\/Pulldown_Menus.jpg\" title=\"HTML\/CSS\/Javascript Pulldown Menus Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">HTML\/CSS\/Javascript Pulldown Menus Primer Tutorial<\/p><\/div>\n<p>Here is a tutorial that introduces you to the website idea of Pulldown Menus.   What is a Pulldown Menu?   Glad you asked.  Pulldown Menus let you present a set of links without the clutter until you choose to &#8220;let the clutter in&#8221;.   We are not showing a jQuery solution here, as we have simplified it quite a bit, but there are good jQuery approaches to Pulldown Menu requirements, such as shown for <a target=_blank title='jQuery UI Accordian Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=965'>jQuery UI Accordian Primer Tutorial<\/a>.   As you can imagine, Pulldown Menus are very popular with Mobile App developers and this <a target=_blank title='Android App Pulldown Menus demo' href='https:\/\/play.google.com\/store\/apps\/details?id=com.pulldownmenu.example&#038;hl=en'>link<\/a> goes to an Android mobile app advice demo page.<\/p>\n<p>Thanks to Wikipedia for the data about Mountain Heights on Earth which helped with the content of this tutorial.<\/p>\n<p>This tutorial also touched on the idea of transparency with a png background image using GIMP, and I found this <a target=_blank title='GIMP png transparency advice' href='http:\/\/geekswithblogs.net\/TimH\/archive\/2006\/03\/20\/72797.aspx'>link<\/a> really helpful.<\/p>\n<p>This tutorial builds on the  <a target=_blank title='HTML\/CSS\/Javascript Sliding Menus Primer Tutorial' href='#slmenuid'>HTML\/CSS\/Javascript Sliding Menus Primer Tutorial<\/a> presented below, and only differs in its CSS to program code from Sliding Menus to Pulldown Menus, which you can verify for yourself by comparing the two program code sources in links just below and way below.<\/p>\n<p>Let&#8217;s see some  <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/PulldownMenus\/'>HTML and CSS and Javascript<\/a> code in live action for this tutorial where you use a Pulldown Menu. <\/p>\n<p>Link to some downloadable HTML programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/PulldownMenus\/pulldown_menus.html_GETME' title='Download me'>pulldown_menus.html<\/a>.\n<\/p>\n<p>Regarding this topic I really like and got help from <em>&#8220;JavaScript &amp; Ajax&#8221; seventh edition by Tom Negrino and Dori Smith<\/em> <\/p>\n<p><strong><em>Did you know?<\/em><\/strong><\/p>\n<p>You may notice that the word Javascript does not appear within the code of pulldown_menus.html as above, so you may wonder how it can be claimed to involve Javascript.   The reason is that Javascript is the default language of HTML element event code, so, just as you can have <br \/><em>&lt;a href=&#8221;<a target=_blank title='Two Ronnies' href='http:\/\/www.youtube.com\/watch?v=h-mX9T2qyIQ#zkWMcRlE1mQ'>http:\/\/www.youtube.com\/watch?v=h-mX9T2qyIQ#zkWMcRlE1mQ<\/a>&#8221; onclick=&#8221;alert(&#8216;FUNEX?&#8217;);'&#8221; title=&#8221;Two Ronnies Question&#8221;&gt;FUNEX?&lt;\/a&gt;<\/em> <br \/>you can just as well use syntax like <br \/><em>&lt;a href=&#8221;<a target=_blank title='Two Ronnies' href='http:\/\/www.youtube.com\/watch?v=h-mX9T2qyIQ#zkWMcRlE1mQ'>http:\/\/www.youtube.com\/watch?v=h-mX9T2qyIQ#zkWMcRlE1mQ<\/a>&#8221; onclick=&#8221;Javascript: alert(&#8216;S,VFX&#8217;);'&#8221; title=&#8221;Two Ronnies Answer&#8221;&gt;S,VFX&lt;\/a&gt; <\/em><\/p>\n<p>CSS doesn&#8217;t appear either, but when CSS is written inline (within the HTML) it just resides within <em>&lt;style&gt;<\/em> and  <em>&lt;\/style&gt;<\/em> within  <em>&lt;head&gt;<\/em> and  <em>&lt;\/head&gt;<\/em> within  <em>&lt;html&gt;<\/em> and  <em>&lt;\/html&gt;<\/em> &#8230; have a read of <a target=_blank title='Cascading Style Sheets Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=736'>Cascading Style Sheets Primer Tutorial<\/a> or visit the &#8220;spiritual home&#8221; of HTML or CSS or Javascript at <a target=_blank title='w3schools' href='http:\/\/www.w3schools.com\/'>w3schools<\/a> and learn at a fundamental level.\n<\/p>\n<hr \/>\n<p id='slmenuid'>Previous <a target=_blank title='HTML\/CSS\/Javascript Sliding Menus Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=3252'>HTML\/CSS\/Javascript Sliding Menus Primer Tutorial<\/a> below:<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/SlidingMenus\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"HTML\/CSS\/Javascript Sliding Menus Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/SlidingMenus\/Sliding_Menus.jpg\" title=\"HTML\/CSS\/Javascript Sliding Menus Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">HTML\/CSS\/Javascript Sliding Menus Primer Tutorial<\/p><\/div>\n<p>Here is a tutorial that introduces you to the website idea of Sliding Menus.   What is a Sliding Menu?   Glad you asked.  Sliding Menus let you present a set of links without the clutter until you choose to &#8220;let the clutter in&#8221;.   We are not showing a jQuery solution here, as we have simplified it quite a bit, but there are good jQuery approaches to Sliding Menu requirements, such as shown for <a target=_blank title='jQuery UI Accordian Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=965'>jQuery UI Accordian Primer Tutorial<\/a>.   As you can imagine, Sliding Menus are very popular with Mobile App developers and this <a target=_blank title='Android App Sliding Menus demo' href='https:\/\/play.google.com\/store\/apps\/details?id=com.slidingmenu.example&#038;hl=en'>link<\/a> goes to an Android mobile app advice demo page.<\/p>\n<p>Thanks to Wikipedia for the data about Mountain Heights on Earth which helped with the content of this tutorial.<\/p>\n<p>This tutorial also touched on the idea of transparency with a png background image using GIMP, and I found this <a target=_blank title='GIMP png transparency advice' href='http:\/\/geekswithblogs.net\/TimH\/archive\/2006\/03\/20\/72797.aspx'>link<\/a> really helpful.<\/p>\n<p>Let&#8217;s see some  <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/SlidingMenus\/'>HTML and CSS and Javascript<\/a> code in live action for this tutorial where you use a Sliding Menu. <\/p>\n<p>Link to some downloadable HTML programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/SlidingMenus\/sliding_menus.html_GETME' title='Download me'>sliding_menus.html<\/a>.\n<\/p>\n<p>Regarding this topic I really like and got help from <em>&#8220;JavaScript &amp; Ajax&#8221; seventh edition by Tom Negrino and Dori Smith<\/em> <\/p>\n<p><strong><em>Did you know?<\/em><\/strong><\/p>\n<p>You may notice that the word Javascript does not appear within the code of sliding_menus.html as above, so you may wonder how it can be claimed to involve Javascript.   The reason is that Javascript is the default language of HTML element event code, so, just as you can have <br \/><em>&lt;a href=&#8221;<a target=_blank title='Two Ronnies' href='http:\/\/www.youtube.com\/watch?v=h-mX9T2qyIQ#zkWMcRlE1mQ'>http:\/\/www.youtube.com\/watch?v=h-mX9T2qyIQ#zkWMcRlE1mQ<\/a>&#8221; onclick=&#8221;alert(&#8216;FUNEX?&#8217;);'&#8221; title=&#8221;Two Ronnies Question&#8221;&gt;FUNEX?&lt;\/a&gt;<\/em> <br \/>you can just as well use syntax like <br \/><em>&lt;a href=&#8221;<a target=_blank title='Two Ronnies' href='http:\/\/www.youtube.com\/watch?v=h-mX9T2qyIQ#zkWMcRlE1mQ'>http:\/\/www.youtube.com\/watch?v=h-mX9T2qyIQ#zkWMcRlE1mQ<\/a>&#8221; onclick=&#8221;Javascript: alert(&#8216;S,VFX&#8217;);'&#8221; title=&#8221;Two Ronnies Answer&#8221;&gt;S,VFX&lt;\/a&gt; <\/em><\/p>\n<p>CSS doesn&#8217;t appear either, but when CSS is written inline (within the HTML) it just resides within <em>&lt;style&gt;<\/em> and  <em>&lt;\/style&gt;<\/em> within  <em>&lt;head&gt;<\/em> and  <em>&lt;\/head&gt;<\/em> within  <em>&lt;html&gt;<\/em> and  <em>&lt;\/html&gt;<\/em> &#8230; have a read of <a target=_blank title='Cascading Style Sheets Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=736'>Cascading Style Sheets Primer Tutorial<\/a> or visit the &#8220;spiritual home&#8221; of HTML or CSS or Javascript at <a target=_blank title='w3schools' href='http:\/\/www.w3schools.com\/'>w3schools<\/a> and learn at a fundamental level.\n<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d3252' onclick='var dv=document.getElementById(\"d3252\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Javascript\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d3252' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d3521' onclick='var dv=document.getElementById(\"d3521\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Javascript\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d3521' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d43919' onclick='var dv=document.getElementById(\"d43919\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/css\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d439198' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>When we last discussed pulldown menus with HTML\/CSS\/Javascript Pulldown Menus Primer Tutorial we didn&#8217;t involve any blocks of Javascript code in the document.head section of the webpage, and no document.body onload event logic. As of today, that is not the &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/htmlcssjavascript-pulldown-menus-javascript-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,37],"tags":[281,2806,2855,354,576,652,1807,870,997,4648,2854,1319],"class_list":["post-43919","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-css","tag-document-head","tag-documentbody","tag-dom","tag-html","tag-javascript","tag-link","tag-onload","tag-programming","tag-pulldown-menu","tag-queryselectorall","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/43919"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=43919"}],"version-history":[{"count":7,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/43919\/revisions"}],"predecessor-version":[{"id":49456,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/43919\/revisions\/49456"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=43919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=43919"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=43919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}