Front End Technology Articles

Page 544 of 652

How to create a div element in jQuery?

Nizam Techs
Nizam Techs
Updated on 12-Jun-2020 1K+ Views

They are many way to add a div using jquery , but as the requirement says  on click of any square we have to addd a div.  The following code below will help in adding a div on click Click on any square below to see the result                               $(".div").on("click",function(){ $('#box').append(   $('')     .attr("id", "newDiv1")     .addClass("div")     .append("")       .text("hello world")     ); });

Read More

How do I check if an element is hidden in jQuery?

Ricky Barnes
Ricky Barnes
Updated on 12-Jun-2020 265 Views

Using jQuery, you can detect if a specific element in the page is hidden or visible with is(:visible). You can try to run the following code to learn how to check if an element is hidden in jQuery or not −ExampleLive Demo           jQuery Selector                      $(document).ready(function() {          $("#button1").click(function(){            var visible = $('#myElement').is(':visible');                      if(visible) {               alert("input element is visible");                    }            else            {               alert("input element is hidden");            }          });         });                                     Check Visibility    

Read More

How to parse JSON object in JavaScript?

Vikyath Ram
Vikyath Ram
Updated on 12-Jun-2020 727 Views

ExampleTo parse JSON object in JavaScript, implement the following code −                    myData = JSON.parse('{"event1":{"title":"Employment period","start":"12\/29\/2011 10:20 ","end":"12\/15\/2013 00:00 "},"event2":{"title":"Employment period","start":"12\/14\/2011 10:20 ","end":"12\/18\/2013 00:00 "}}')          myArray = []          for(var e in myData){             var dataCopy = myData[e]             for(key in dataCopy){                if(key == "start" || key == "end"){                   dataCopy[key] = new Date(dataCopy[key])                }             }             myArray.push(dataCopy)          }          document.write(JSON.stringify(myArray));          

Read More

How can I pass a parameter to a setTimeout() callback?

Daniol Thomas
Daniol Thomas
Updated on 12-Jun-2020 2K+ Views

To pass a parameter to setTimeout() callback, use the following syntax −setTimeout(functionname, milliseconds, arg1, arg2, arg3...)The following are the parameters −function name − The function name for the function to be executed.milliseconds − The number of milliseconds.arg1, arg2, arg3 − These are the arguments passed to the function.ExampleYou can try to run the following code to pass a parameter to a setTimeout() callbackLive Demo           Submit                function timeFunction() {             setTimeout(function(){ alert("After 5 seconds!"); }, 5000);          }          Click the above button and wait for 5 seconds.    

Read More

HTML DOM Input Button Object

Sharon Christine
Sharon Christine
Updated on 12-Jun-2020 284 Views

The HTML DOM Input Button Object serves as an input HTML element with type attribute as “button”.Let us see how to create an Input Button Object −syntaxFollowing is the syntax −var newButton = document.createElement(“INPUT”); newButton.setAttribute(“type”, ”value”);Here, value can be “button”, “submit” & “reset”.propertiesFollowing are the properties of Input Button Object −PropertyExplanationautofocusThis property returns and alter the value of autofocus attribute of an input button in HTML.defaultValueIt returns and modify the default value of an input button in HTML.disabledIt returns and alter the value of disabled attribute of an input button in HTML.formIt returns the reference of the form which enclose ...

Read More

What is the syntax for leading bang! in JavaScript function?

Nancy Den
Nancy Den
Updated on 12-Jun-2020 214 Views

To execute an anonymous function you need to use the leading bang! or any other symbol −!function(){    // do stuff }();You can also write it like −+function(){    // do stuff }();Even the following is an acceptable syntax −~function(){    // do stuff    return 0; }( );

Read More

How to call multiple JavaScript functions in onclick event?

Nishtha Thakur
Nishtha Thakur
Updated on 12-Jun-2020 2K+ Views

To call multiple JavaScript functions in on click event, use a semicolon as shown below −onclick="Display1();Display2()"ExampleLive Demo                    function Display1() {             document.write ("Hello there!");          }          function Display2() {             document.write ("Hello World!");          }                     Click the following button to call the function                          

Read More

What is the use of JavaScript eval function?

Vrundesha Joshi
Vrundesha Joshi
Updated on 12-Jun-2020 396 Views

The JavaScript eval() is used to execute an argument. The code gets execute slower when the eval() method is used. It also has security implementations since it has a different scope of execution. In addition, use it to evaluate a string as a JavaScript expression.The eval() method is not suggested to use in JavaScript since it executes slower and improper usage opens your website to injection attacks.ExampleHere’s how you can implement eval() functionLive Demo                    var a = 30;          var b = 12;          var res1 = eval("a * b") + "";          var res2 = eval("5 + 10") + "";          document.write(res1);          document.write(res2);          

Read More

What is "function*" in JavaScript?

Smita Kapse
Smita Kapse
Updated on 12-Jun-2020 335 Views

The function* declaration is used to define a generator function. It returns a Generator object. Generator Functions allows execution of code in between when a function is exited and resumed later. So, generators can be used to manage flow control in a code.SyntaxHere’s the syntax −function *myFunction() {} // or function* myFunction() {} // or function*myFunction() {}Let’s see how to use generator functionExampleLive Demo                    function* display() {             var num = 1;             while (num < 5)       ...

Read More

How to write a custom jQuery plugin?

Ricky Barnes
Ricky Barnes
Updated on 12-Jun-2020 329 Views

To create a jQuery plugin, first create a file named jquery-demoplugin.js with the following code. This is our plugin code. Here, demoplugin is the name of our plugin. You can add any name to your custom plugin −(function ( $ ) {    $.fn.demoplugin = function( options ) {       var web = $.extend({          name: 'example'       }, options );       return this.append('Website: ' + web.name + '.com');    }; }( jQuery ));Now, to load it, add to the HTML file, new.html −    $( document ).ready(function() {       $( '#content ).demoplugin();    });

Read More
Showing 5431–5440 of 6,517 articles
« Prev 1 542 543 544 545 546 652 Next »
Advertisements