{"id":202,"date":"2024-05-21T09:44:55","date_gmt":"2024-05-21T07:44:55","guid":{"rendered":"https:\/\/blog.sutilweb.eu\/?page_id=202"},"modified":"2024-05-21T09:44:55","modified_gmt":"2024-05-21T07:44:55","slug":"39-javascript-y-html","status":"publish","type":"page","link":"https:\/\/sutilweb.eu\/index.php\/lenguajes\/html5\/html5-manual\/39-javascript-y-html\/","title":{"rendered":"39. Javascript y HTML"},"content":{"rendered":"\n<p><strong>JavaScript<\/strong> hace que las p\u00e1ginas HTML sean m\u00e1s din\u00e1micas e interactivas.<\/p>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"es\"&gt;\n&lt;head&gt;\n\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;h1&gt;Mi primer Javascript&lt;\/h1&gt;\n&lt;button type=\"button\" onClick=\"document.getElementById('demo').innerHTML=Date()\"&gt;\nHaz clic para mostrar la fecha&lt;\/button&gt;\n&lt;p id=\"demo\"&gt;&lt;\/p&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">La etiqueta HTML &lt;script&gt;<\/h2>\n\n\n\n<p>La etiqueta HTML <strong><em>&lt;script&gt;<\/em><\/strong> se utiliza para definir un script del lado del cliente (<strong>JavaScript<\/strong>).&nbsp;El elemento <strong><em>&lt;script&gt;<\/em><\/strong> contiene sentencias de script o apunta a un archivo de script externo a trav\u00e9s del atributo <strong><em>src<\/em><\/strong>.&nbsp;Los usos comunes de <strong>JavaScript<\/strong> son la <strong>manipulaci\u00f3n de im\u00e1genes<\/strong>, la <strong>validaci\u00f3n de formularios<\/strong> y los <strong>cambios din\u00e1micos de contenido<\/strong>.&nbsp;Para seleccionar un elemento <strong>HTML<\/strong>, <strong>JavaScript<\/strong> suele utilizar el m\u00e9todo <strong><em>document.getElementById()<\/em><\/strong>.&nbsp;Este ejemplo de JavaScript escribe \u00ab\u00a1Hola, JavaScript!\u00bb en un elemento HTML con id=\u00bbdemo\u00bb.<\/p>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"es\"&gt;\n&lt;head&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;h1&gt;Ejm Javascript&lt;\/h1&gt;\n&lt;p&gt;Este ejm escribe \"Hola Javascript\" dentro de un elemento con un id=\"demo\"&lt;\/p&gt;\n\n&lt;p id=\"demo\"&gt;&lt;\/p&gt;\n\n&lt;script&gt;\ndocument.getElementById(\"demo\").innerHTML=\"Hola Javascript\";\n&lt;\/script&gt;\n&lt;\/body&gt;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;\/html&gt;\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Una muestra de JavaScript<\/h2>\n\n\n\n<p>Veamos algunos ejms de lo que podemos hacer con Javascript.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Javascript puede cambiar contenido<\/h3>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"es\"&gt;\n&lt;head&gt;\n\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;h1&gt;Mi primer Javascript&lt;\/h1&gt;\n&lt;h2&gt;Javascript puede cambiar el contenido de un elemento HTML&lt;\/h2&gt;\n\n&lt;button type=\"button\" onClick=\"myFunction()\"&gt;Haz clic&lt;\/button&gt;\n\n&lt;p id=\"demo\"&gt;Esto es una demostraci\u00f3n de Javascript&lt;\/p&gt;\n\n&lt;script&gt;\nfunction myFunction(){\ndocument.getElementById(\"demo\").innerHTML=\"Hola Javascript\";\n}\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Javascript puede cambiar estilos<\/h3>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"es\"&gt;\n&lt;body&gt;\n&lt;h1&gt;Mi primer Javascript&lt;\/h1&gt;\n&lt;p id=\"demo\"&gt;Javascript puede cambiar estilos en elementos HTML&lt;\/p&gt;\n\n&lt;script&gt;\nfunction myFunction(){\ndocument.getElementById(\"demo\").style.fontSize=\"25px\";\ndocument.getElementById(\"demo\").style.color=\"red\";\ndocument.getElementById(\"demo\").style.backgroundColor=\"yellow\";\n}\n&lt;\/script&gt;\n\n&lt;button type=\"button\" onClick=\"myFunction()\"&gt;Haz clic&lt;\/button&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">La etiqueta &lt;noscript&gt;<\/h2>\n\n\n\n<p>La etiqueta HTML <strong><em>&lt;noscript&gt;<\/em><\/strong> define un contenido alternativo que se mostrar\u00e1 a los usuarios que tienen scripts deshabilitados en su navegador o tienen un navegador que no admite scripts.<\/p>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;body&gt;\n\n&lt;p id=\"demo\"&gt;&lt;\/p&gt;\n\n&lt;script&gt;\ndocument.getElementById(\"demo\").innerHTML = \"Hola Javascript!\";\n&lt;\/script&gt;\n\n&lt;noscript&gt;Tu navegador no soporta Javascript&lt;\/noscript&gt;\n\n&lt;p&gt;Un navegador sin soporte para Javascript s\u00f3lo mostrar\u00e1 el\ntexto escrito dentro del elemento noscript.&lt;\/p&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript hace que las p\u00e1ginas HTML sean m\u00e1s din\u00e1micas e interactivas. Ejm &lt;!DOCTYPE html&gt; &lt;html lang=\u00bbes\u00bb&gt; &lt;head&gt; &lt;\/head&gt; &lt;body&gt; &lt;h1&gt;Mi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":41,"menu_order":38,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-202","page","type-page","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Sutil Web","author_link":"https:\/\/sutilweb.eu\/index.php\/author\/sutilweb\/"},"uagb_comment_info":0,"uagb_excerpt":"JavaScript hace que las p\u00e1ginas HTML sean m\u00e1s din\u00e1micas e interactivas. Ejm &lt;!DOCTYPE html&gt; &lt;html lang=\"es\"&gt; &lt;head&gt; &lt;\/head&gt; &lt;body&gt; &lt;h1&gt;Mi [&hellip;]","_links":{"self":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/comments?post=202"}],"version-history":[{"count":2,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/202\/revisions"}],"predecessor-version":[{"id":204,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/202\/revisions\/204"}],"up":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/41"}],"wp:attachment":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/media?parent=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}