Subpanels of a module

I’m working hard on a preview of the images that are in the history subpanel as an attachment
And my problem resists in that:
when loading and reloading the page with the subpanel closed, the js code does not execute the preview
But if I open it and reload again if it does

What I’m I missing of?

I use in my js

$('#imgdiv').attr('display', 'none');
    $("#list_subpanel_history > table > tbody > tr.oddListRowS1").mouseover(function(){   
        var x = $(this).children('td').eq(1).children('a').attr('href');
        var a = x.split("="); //console.log(a);
        var r = 'upload/' + a[3]; console.log(r);     
        $("#imgdiv").attr('src', r); 
        $('#imgdiv').attr('display', 'block');

$("#list_subpanel_history > table > tbody > tr.oddListRowS1").mouseout(function(){    
        $("#imgdiv").attr('src', ''); 
        $('#imgdiv').attr('display', 'none');

en oddListRowS1 y en los elementos evenListRowS1

Thanks for the help in advance!
I am new and I am starting to get involved with suitecrm

It was also very difficult for me to find related topics in the forum and on the web

Thank you!