JavaScript - jQuery - Ajax


  1. » Marius
    I am creating a website with HTML and JavaScript that relies on the data of an XML file hosted on a separate domain.
    I can achieve this with...
    Last post » MarPlo
    Try using the the fetch api.

    fetch('//example.com/file_address')
    .then( response => response.text() )
    .then( response => {
    //response is...


  2. » Marius
    I have a for() loop like this one which shows what i want to do.

    for(var i=0; i<15; i++) {
    // Add data in html
    // When data has a specified...
    Last post » MarPlo
    To achieve your goal you can add the if() condition within the loop, and check the values of your data.
    If it has the specified value, sets the new...


  3. » Marius
    With the good old for loop in Javascript I can do things like:

    for (let i=0; i<bla.length; i+=2){
    //...
    }

    So for every count, I can skip...
    Last post » MarPlo
    You may add an if() statement within the for...of loop, like in the following example (the original index is preserved).

    for (const of...


  4. » Marius
    How can I make that when an option from dropdowna <select> list is selected, the value of that option be displayed into a Div.
    I have this...
    Last post » MarPlo
    You have to start with a <select> element which raises a 'change' event when an option is selected.
    Inside that event, 'this.value' refers to...


  5. » Marius
    Say I have the following array of persons:

    const arr =

    And I want to find a certain person (name) in this array, and put it as the first...
    Last post » Admin
    You could sort the array with the sort() method.
    This approach moves all objects with the wanted 'name' to top.

    const arr = ;
    let first =...


  6. » Marius
    I have a nested object in JavaScript that looks like this:

    const yo = {
    one: {
    value: 0,
    mission: 17},
    two: {
    value: 18,
    mission: 3},...
    Last post » Admin
    Try combine the Object.values() and map() methods, like in the following example:

    const yo = {
    one: {
    value: 9,
    mission: 17
    },
    two: {...


  7. » Marius
    I’m trying to replace all spaces within a string with hyphens.
    I tried this:

    let str ='This is my text';
    str = str.replace(/\s/, '-');...
    Last post » Admin
    Add the global search flag (/g ) to your regex to match all occurrences.

    let str ='This is my text';
    str = str.replace(/\s/g, '-');...


  8. » Marius
    The code below sends the 30s event do Google Analytics after 30 seconds a user enters a page.

    setTimeout(function(){
    gtag('event', '30s');
    },...
    Last post » Admin
    You can watch for when a tab loses focus by using the event listener 'visibilitychange'. When the visibility changes, you can use 'document.hidden'...


  9. » Marius
    I have a JavaScript code that adds an input field for a user:

    var user = O'Conner, John ;
    b.innerHTML += <input type='hidden' value=' + user +...
    Last post » Admin
    You can replace the character with its HTML entity.

    As for ' - It can either be &rsquo; or &lsquo;

    var user = O'Conner, John ;
    user =...


  10. » Marius
    The idea is that when i click on a button, old content gets replaced by new HTML content added with javascript.
    I want that new content to appear...
    Last post » Admin
    To trigger a CSS transition, change the CSS state after you inserted the HTML. You can do this by changing a class (on the container or an inserted...


  11. » Marius
    I want to create a toggle function for my localStorage where I want it to remember the user's choice.
    I want it load the current preference on page...
    Last post » Admin
    You can't keep boolean in localStorage. That's why you have an error. Try to keep, for example, 0 for False and 1 for True. But remember that...


  12. » Marius
    I've a website loader in GIF format but it doesn't appear because the page is loaded in 0.01 seconds.
    Is there possible to set a loading time to 2...
    Last post » Admin
    Here is an example of a preloader with jQuery using the delay() method (2 sec = 2000), wrapped inside the 'load' event.

    <style>
    .loading...


  13. » Marius
    What's an efficient way of implementing the dotProduct method (to get the Dot product of two arrays) without importing any new Javascript libraries?...
    Last post » Admin
    Here is a method.
    Use the map() function to create a new array with multiplied results of each index and the reduce() function to sum the values of...


  14. » Marius
    I'm trying to push an array into the same array in javascript, But it doesn't seem to be working; the third element is added continuously.
    Here is...
    Last post » Admin
    You are trying to push the same reference to the array. So, when the array updated later, the array inside the element will be updated as well.
    To...


  15. » Marius
    I have an array of objects, and for plotting a graph I need to split it into 3 different arrays. How to do it using JS?

    const dataOverview = ;

    I...
    Last post » Admin
    It is very simple, you just use the map() function.

    var series1 = dataOverview.map(x => x.series1);
    var series2 = dataOverview.map(x =>...


  16. » Marius
    Why the function.call() behaves differently with and without ' this ', in JavaScript?
    The result with 'this' in test.call() is same when 'this' is...
    Last post » Admin
    The call() function require the first parameter as 'this' object, if you do not need it, just pass null .

    test.call(null, ...args);

    In your...


  17. » Marius
    I have the following problem:
    1. eliminate thousand separators(,) 5,555 to 5555.
    2. if the user inputs 55,66 replace , with . and get the value...
    Last post » Admin
    Try the function from the following code:

    function salNr(s){
    //If there is comma before the last two digit, replace it with dot, else remove...


  18. » Marius
    I have this code (ajax is async):

    function echoHello(){
    return $.ajax({
    //this will return hello ;
    });
    }

    function echoWorld(){
    return world...
    Last post » Admin
    Ajax makes a call to the web server and is asynchronous. You don't know how long it will take. It is the same as:

    setTimeout(_ => {...


  19. » Marius
    I have a question: i want to change keys into a JavaScript object if their value is number, for example, I have the following object:

    const...
    Last post » Admin
    To change a key into a JavaScript object, you need to clone the value with the new key, and then you delete the old key in the object.

    const...


  20. » Marius
    I can't figure out how I can change the following object in JavaScript:

    { first : , second : , third : }

    to:

    { de : , ab : }

    I want to...
    Last post » Admin
    You have to loop the array and for each item in the array check if an array for that value exists in the accumulator or not before adding it:...


  21. » Marius
    I have the following html and JavaScript code. An input text box and a button.

    <input type='text' id='backwards-input'>
    <button...
    Last post » Admin
    Try use and study the following code:

    <input type='text' id='backwards-input'>
    <button id='backwards-button'>Button</button>...


  22. » Marius
    I have 3 arrays of objects in JavaScript:

    const fruits =

    const car =

    const books =

    One temporary array where I will store random objects...
    Last post » Admin
    You need to get two random numbers:
    - the first to decide which group to pick,
    - the second to pick an item from that.

    We generate a random...


  23. » JanMolendijk
    Hello Coursesweb I`m unknown with javascripts ????

    I would like to add function minutes to this script
    on each minute an diferent text added to...
    Last post » Admin
    Hello,
    Try the following script.

    <div id='addtxtmin' style='color:#00d; font-size:20px; font-weight:700'></div>
    <script>
    const...


  24. » JanMolendijk
    Hello Coursesweb I do not known mutch about javascipts
    & for view hours I gambling to try to get images in this javascript

    I try with...
    Last post » JanMolendijk
    You had the best support on the internet,
    mutch better then stackoverflow.

    i learnt alot from you it was really valuable
    + Thanks for all you...


  25. » PloMar
    I have this JS script:
    <script>
    function blockToggle(type,blockee,elem){
    var conf = confirm( Press OK to confirm the ' +type+ ' action );...
    Last post » warrenfelsh
    In JavaScript almost everything is an object, null and undefined are exception. When you try to access an undefined variable it always returns...