Click here to Skip to main content
15,868,141 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Best ReactJS tutorial? Pin
Le centriste4-Sep-19 3:57
Le centriste4-Sep-19 3:57 
QuestionHow to call function second time? Pin
Tarun Rathore 23-May-19 19:28
Tarun Rathore 23-May-19 19:28 
GeneralRe: How to call function second time? Pin
Richard MacCutchan23-May-19 21:56
mveRichard MacCutchan23-May-19 21:56 
AnswerRe: How to call function second time? Pin
Shraddha_Patel21-Oct-19 20:04
Shraddha_Patel21-Oct-19 20:04 
QuestionExplain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any? Pin
Shraddha_Patel20-May-19 17:38
Shraddha_Patel20-May-19 17:38 
AnswerRe: Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any? Pin
Richard MacCutchan20-May-19 21:03
mveRichard MacCutchan20-May-19 21:03 
AnswerRe: Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any? Pin
ZurdoDev21-May-19 2:03
professionalZurdoDev21-May-19 2:03 
QuestionHow to give unique ids to changing divs? Pin
Tarun Rathore 18-May-19 9:48
Tarun Rathore 18-May-19 9:48 
The function displays values of options property of array in separate divs. I want to give each div a unique id, which I have given, but the first displayed divs are replaced by totally different divs on click; so I am unable to give ids to each div. I want that divs should remain same and only the values should change on click. Presently the ids that I have given are removed when next values are displayed on click.  How can I achieve that?  Thanks for your suggestions.


<button id="btnNext" onclick="showOptions();"> Options </button>

<div id="container"> </div>


var antonyms = [

       {
           question: "soft",
           options: ["dark", "white", "heavy", "hard", "down", "pretty", "butter", "cotton"],
           answer: "hard"

       },

       {
           question: "beautiful",
           options: ["pretty", "ugly", "handsome", "wonderful", "up", "high", "cheerful", "black"],
           answer: "ugly"

       },
    ]


    // Define a method that generates the HTML for one question.


    function showOptions(q)

    {
        let qHtml = '<div class="option">' + q.question + '</div>';

        qHtml += q.options.map(o => '<div class="option">' + o + '</div>').join("");

        return qHtml;

    }

```
    // Start showing the first question. Click event will show next question.


    let container = document.getElementById("container");

    let button = document.getElementById("btnNext");

    let qIdx = 0;

    container.innerHTML = showOptions(antonyms[qIdx]);

    button.addEventListener("click", function()

        {

            qIdx += 1;

            if (qIdx < antonyms.length)

                container.innerHTML = showOptions(antonyms[qIdx]);

            else

                button.disabled = true;

        });

```
    // Giving unique id to each option div

    $('#container div').each(function(eq, el) {

        el = $(el);

        if (typeof(el.attr('id')) === "undefined") {

            el.attr('id', 'box-' + eq);

        }

    });

AnswerRe: How to give unique ids to changing divs? Pin
ZurdoDev21-May-19 2:04
professionalZurdoDev21-May-19 2:04 
QuestionUsing XML Pin
V.28-Apr-19 20:57
professionalV.28-Apr-19 20:57 
SuggestionRe: Using XML Pin
Richard MacCutchan28-Apr-19 21:56
mveRichard MacCutchan28-Apr-19 21:56 
GeneralRe: Using XML Pin
V.28-Apr-19 22:21
professionalV.28-Apr-19 22:21 
GeneralRe: Using XML Pin
Richard MacCutchan28-Apr-19 22:25
mveRichard MacCutchan28-Apr-19 22:25 
GeneralRe: Using XML Pin
V.28-Apr-19 22:38
professionalV.28-Apr-19 22:38 
AnswerRe: Using XML Pin
Graham Breach29-Apr-19 2:35
Graham Breach29-Apr-19 2:35 
GeneralRe: Using XML Pin
V.30-Apr-19 1:38
professionalV.30-Apr-19 1:38 
Question<SOLVED> Why is my validation script not working? Pin
samflex26-Apr-19 4:20
samflex26-Apr-19 4:20 
AnswerRe: Why is my validation script not working? Pin
Richard Deeming26-Apr-19 4:31
mveRichard Deeming26-Apr-19 4:31 
GeneralRe: Why is my validation script not working? Pin
samflex26-Apr-19 4:45
samflex26-Apr-19 4:45 
GeneralRe: Why is my validation script not working? Pin
Richard Deeming26-Apr-19 4:49
mveRichard Deeming26-Apr-19 4:49 
GeneralRe: Why is my validation script not working? Pin
samflex26-Apr-19 5:04
samflex26-Apr-19 5:04 
Questionjavascript Pin
Member 1418486021-Apr-19 23:48
Member 1418486021-Apr-19 23:48 
AnswerRe: javascript Pin
W Balboos, GHB15-May-19 4:08
W Balboos, GHB15-May-19 4:08 
AnswerRe: javascript Pin
Shraddha_Patel5-Nov-19 17:30
Shraddha_Patel5-Nov-19 17:30 
QuestionAdding Blank pages to PDF when requirements met Pin
Member 142140864-Apr-19 15:03
Member 142140864-Apr-19 15:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.