How to display HTML, javaScripts codes on Web.

How to display HTML, javaScripts codes on Web.

CodePen.io testing

<pre><code> … </code></pre>

<pre></pre> is for pre-formatted code

<code></code> is what to use to display code in HTML.
document.getElementById(‘mydiv’)
document.querySelectorAll(‘.button’);
document.querySelector(‘#mydiv’)
document.querySelectorAll(‘.myclass’)
$(‘#mydiv’)
$(‘.myclass’)

Here I am using <pre><code>…</pre></code> below:


//Javascript Example
document.addEventListener('DOMContentLoaded', function() {

    var element = document.querySelector('#mydiv');
    element.addEventListener('click', function() {
      // do something
    });
    
})
    
//JQuery Example
$( document ).ready(function() {

    $("#mydiv").click(function() {
      // do something
    });

});

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s