1

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>
Aalexander
  • 4,987
  • 3
  • 11
  • 34

1 Answers1

1

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'];

}
Oscar
  • 13,594
  • 8
  • 47
  • 75