0

Am working on some custom tabs built using Jquery. When the user selects on a particular tab am capturing the text and storing it in a variable. This works fine but the issue is the variable should be in a global scope so that I can use it in another function (called execValue) outside the function that captures text from selected tab.

Markup

<ul>
    <li class="columns">
        <label><span>Holiday/Business Trip</span></label>
    </li>

    <li class="columns">
        <label><span>Winter Sports</span></label>
    </li>

    <li class="columns">
        <label><span>Risky Sports</span></label>
    </li>

    <li class="columns">
        <label><span>Study</span></label>
    </li>
</ul>

Logic

let purpose = false;
let value = "";
$(".columns").click(function (value) {
    if (!purpose) {
        let reason = $(this).text();
        if(reason.trim() == "Holiday/Business Trip"){
            value = 'holiday';
        }
        if(reason.trim() == "Winter Sports"){
            value = 'Winter';
        }
        if(reason.trim() == "Risky Sports"){
            value = 'Risky';
        }
        if(reason.trim() == "Study"){
            value = 'study';
        }      
        console.log(value);
    }
});


function execValue(){
    //Capture value here
}
Martin
  • 547
  • 2
  • 11
  • 40

0 Answers0