JavaScript - jQuery - Ajax

  1. » PloMar
    How to add (append) text in textarea using jquery without removing previous text?
    I have this code, but it only works for first time, when i change...
    Last post » MarPlo
    Inside the dom the value and text attributes are stored separately. When you use append the text is appended but the value is blanked because it is...

  2. » PloMar
    I'm drawing text in an HTML5 canvas on top of an image. I want to calculate a font size so that the string will span 200 pixels width.
    Last post » MarPlo
    The fillText() method has an optional fourth argument, which is the max width to render the string.
    - MDN's documentation says:
    maxWidth - the...

  3. » PloMar
    Hello all
    Anyone know how to calculate the number of characters that will fill one line of a div with a fixed width (for example 200px), using...
    Last post » MarPlo
    You can use this formula to get the width of the line for a given number of characters (CPL):
    Width = CPL * (font-size / font-constant)
    - CPL...

  4. » PloMar
    I use this code to animate position of a Div when is hovered. I move it with 2500 animation speed.
    How do I change speed of this animation to 800,...
    Last post » Admin
    Try with the dequeue() function (Execute the next function on the queue for the matched elements).
    <div id= dv >Animate Div</div>...

  5. » PloMar
    Let say I have this html:
    <div id= parent >
    <div id= c1 >Content child 1</div>
    <p id= c2 >Paragraph ...
    Last post » Admin
    Try with the > selector, it refers to the direct childen.
    1. Example get array with the ID of all direct children.
    <div id= parent >...

  6. » PloMar
    How can I use JavaScript /jQuery to follow the mouse cursor with a DIV in the whole page?
    Last post » Admin
    If you want this effect with pure JavaScript, you can use this code:
    #div_moving {
    position: absolute;
    width: 140px;
    height: 65px...

  7. » PloMar
    I'm playing with jQuery. Now I test the trigger() method.
    I try to trigger a custom method and pass two additional arguments (an object and a...
    Last post » Admin
    When you pass multiple arguments with trigger(), and those arguments aren't a number or a string, you should pass all the additional arguments into...

  8. » PloMar
    I have a Select box and options with IDs of the rows from a MySQL table.
    In that form there are 3 text fields.
    Now, when I select an option from...
    Last post » Admin
    To make that script you need to know how to work with JavaScript /Ajax and with data in JSON format.
    1. Register an onchange event to the Select-box...

  9. » PloMar
    I have an object like this in javascript:
    var obj = {
    prop1: 'val 1',
    prop2: 'val 2',
    prop3: 'val 3'
    What is the best way to retrieve a list...
    Last post » Admin
    You can use the built in Object.keys method:
    var obj = {
    prop1: 'val 1',
    prop2: 'val 2',
    prop3: 'val 3'

    var props = Object.keys(obj);...

  10. » PloMar
    I have an object like this in javascript:
    var obj = {
    prop1: 'val 1',
    prop2: 'val 2',
    prop3: 'val 3'
    What is the best way to remove the...
    Last post » Admin
    To remove a property from a javascript object, you can use the delete instruction.
    var obj = {
    prop1: 'val 1',
    prop2: 'val 2',

  11. » MarPlo
    I have a html table and a button, like this:
    <table id= tb_id border= 1 >
    Last post » Admin
    To append a row in a html table, use this syntax:
    $('#table_id > tbody:last').append('<tr>...</tr>');
    And to hide the pressed...

  12. » MarPlo
    I'm trying to dynamically add and remove items with jQuery when I press the Append /Remove buttons.
    This is the html code:
    <ul id= lists >...
    Last post » Admin
    Use the append() and remove() jquery methods, like in this example:
    <ul id= lists >
    <li>List Item 0</li>

  13. » MarPlo
    I need to serialize an object to JSON in JavaScript. Is there a standard way to do this?
    I have an array defined something like this:
    var countries...
    Last post » Admin
    Use the JSON object methods.
    - To convert an object to a string, use JSON.stringify() :
    var json_string = JSON.stringify(your_object, null, 2);

  14. » MarPlo
    I want to do something like this:
    $( .chkox ).checked(true);
    $( .chkox ).selected(false);
    I wish to set the checked value to check or uncheck...
    Last post » Admin
    Use the prop() method.
    $('.chkbox').prop('checked', true); // checking
    $('.chkox').prop('checked', false); // unchecking
    And if you want to check...

  15. » MarPlo
    Is it posible to run a php function through a javascript function?
    Something like this:
    <div id= php_code >Here will be added the Php Code...
    Last post » Admin
    PHP is evaluated at the server; javascript is evaluated at the client-side/browser, thus you can't call a PHP function from javascript directly. But...

  16. » MarPlo
    Is there any way I can modify the URL of the current page without reloading the page?
    I only need to change the portion after the domain, when a...
    Last post » Admin
    You can use the history.pushState() method to change the url address without refreshing the page.
    It works in modern browsers which suport HTML5....

  17. » MarPlo
    I have written a code that adds a text in canvas on clicking a button.
    And i want to display this text for lets say 2 seconds. How can I make the...
    Last post » Admin
    You have to use setTimeout() to call a function, after a given time, that clears the canvas content.
    Here's a simple demo for writing and clearing...

  18. » MarPlo
    Hi all,
    How can I set the canvas dimensions (width and height) according to window's size, using JavaScript?
    And, if it's possible, to change...
    Last post » Admin
    With self.innerWidth and self.innerHeight you can get the window's width and height. Then, with resize event you can detect when the window is...

  19. » MarPlo
    I have two DIVs that I need to know the calculated browser distance (in width and height) of them.
    Example html:
    <div id= dv1 >div...
    Last post » Admin
    Use the offset() function.
    Something like this should work:
    <div id= dv1 >div 1</div>
    Some text ...<br>

    <div id= dv2 >div...

  20. » MarPlo
    I have an array of integers:
    var array = ;
    Is there a simple way to remove a specific element from an array? The equivalent of something like:...
    Last post » Admin
    Use the indexOf() to find the index of the element you want to remove, then apply splice() to remove it:
    var array = ;
    var index =...

  21. » Marius
    I am using a jQuery script that adds dynamically a Div in the DOM. I am trying to ad onclick event for this div.
    <div class= ui23...
    Last post » Admin
    The live() method for registering events in jQuery is deprecated. Use instead the on() method.
    This is called event delegation ....

  22. » Marius
    Hi there,
    I would like a little advice for a proper way to animate with JavaScript, without using jQuery or other framework, just with pure...
    Last post » Admin
    The JavaScript has a function for animating objects, called requestAnimationFrame() that works in modern browsers (IE 10+)....

  23. » Marius
    Does anyone know how to add option in web page to change the css theme?
    For example, i have two css files: light.css , and dark.css . I want to...
    Last post » Admin
    It can be made with html and javascript:
    - Add an id to the html <link> tag which loads the css file.
    - Create a <select> with...

  24. » Marius
    How to focus on particular part of a web page by using javascript events?
    Let's say I clicked a button and it will scroll down or scroll up to a...
    Last post » MarPlo
    To scroll to a specified element, use the element.scrollIntoView() method (this method scrolls the current element into the visible area of the...

  25. » Marius
    How can I dynamically set /modify the values of certain form elements, more specifically certain input text fields? So far, whenever I load my html...
    Last post » MarPlo
    Add an ID to the input text field, for example:
    <form id= form1 >
    <input type= text name= q01 id= id_i1 maxlength= 1 />...