Search code examples
javascriptfunctiononmousedown

send a mouse over event from one function to another function in javascript


I want to get the id of the font tag and then pass it to the changeText function so that i can display the words in

<font id='1' onmousedown="getID(this)" onmouseup="changeText()"> hello </font>
<script type="text/javascript">

    function getID(el) {   
        var wordID = $(el).attr("id");
        console.log('getID ',wordID);
        return wordID;

    }

    var info = getID()

    words = {'1':'привет','2':'моё','3':'имя','4':'являться','5':'мэтт'}

    function changeText() {
        var display = document.getElementById(info);
        display.innerHTML = '';
        display.innerHTML = words['1'];
    }
  

</script>

Solution

  • You can merge it in a single function, no need of two functions for that, as getID is simply getting a variable..

    function changeText(){
        var wordID = $(el).attr("id");
        var display = document.getElementById(info);
        display.innerHTML = '';
        display.innerHTML = words['1'];
    
    }