Click here to Skip to main content
15,897,891 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionRe: Delete consumer Pin
ZurdoDev7-Aug-19 11:08
professionalZurdoDev7-Aug-19 11:08 
QuestionLooking for Bootstrap, TypeScript,Vue and Vue Router Guide to Building a Navigation Bar Pin
Jammer29-Jun-19 2:45
Jammer29-Jun-19 2:45 
AnswerRe: Looking for Bootstrap, TypeScript,Vue and Vue Router Guide to Building a Navigation Bar Pin
Afzaal Ahmad Zeeshan30-Jul-19 5:37
professionalAfzaal Ahmad Zeeshan30-Jul-19 5:37 
Questionhow to open word file in client side Pin
Member 1447396626-Jun-19 1:32
Member 1447396626-Jun-19 1:32 
AnswerRe: how to open word file in client side Pin
Richard MacCutchan26-Jun-19 1:45
mveRichard MacCutchan26-Jun-19 1:45 
Question(SOLVED) How to activate button on mouse press? Pin
samflex6-Jun-19 4:39
samflex6-Jun-19 4:39 
AnswerRe: How to activate button on mouse press? Pin
Richard Deeming6-Jun-19 5:39
mveRichard Deeming6-Jun-19 5:39 
GeneralRe: How to activate button on mouse press? Pin
samflex6-Jun-19 6:24
samflex6-Jun-19 6:24 
GeneralRe: How to activate button on mouse press? Pin
samflex6-Jun-19 7:21
samflex6-Jun-19 7:21 
GeneralRe: How to activate button on mouse press? Pin
Richard Deeming6-Jun-19 8:03
mveRichard Deeming6-Jun-19 8:03 
GeneralRe: How to activate button on mouse press? Pin
samflex6-Jun-19 9:47
samflex6-Jun-19 9:47 
Questionhow to count product codes from textarea? Pin
Veltix26-May-19 4:11
Veltix26-May-19 4:11 
AnswerRe: how to count product codes from textarea? Pin
jkirkerx27-May-19 11:14
professionaljkirkerx27-May-19 11:14 
QuestionBest ReactJS tutorial? Pin
Corey Cananza26-May-19 3:59
Corey Cananza26-May-19 3:59 
AnswerRe: Best ReactJS tutorial? Pin
Katie Webber30-Jul-19 2:06
professionalKatie Webber30-Jul-19 2:06 
AnswerRe: Best ReactJS tutorial? Pin
Harsh.Shah.ifour13-Aug-19 18:13
professionalHarsh.Shah.ifour13-Aug-19 18:13 
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 

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.