Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   события в элементе (https://javascript.ru/forum/events/74944-sobytiya-v-ehlemente.html)

Conus 19.08.2018 09:39

события в элементе
 
Подскажите пожалуйста,
как задать CustomEvent() или new Event()
что-бы использовать в html коде или setAttribute()
нпример
var event = new Event('build');


function View() 
{  
      var i = document.createElement('div');
           i.textContent = String.fromCharCode(10004) 

          //задам функцию для события известным способом	      
         //    i.addEventListener('build', function (e) { alert()  }, false);
 
         //а надо задать событие в setAttribute  
        i.setAttribute(event, 'new Function');  //   -как это сделать 
        i.Function = function() { alert() } 
					
    return i
}	

document.body.appendChild(View())


или
<div id='x' event='alert|()'></div>

Conus 19.08.2018 13:34

var event = new Event('build');


function View() 
{  
      var i = document.createElement('div');
           i.textContent = String.fromCharCode(10004) 
 
    
        i.setAttribute('build', 'new Function');  
        i.Function = function() { alert() } 
					
    return i
}	

document.body.appendChild(View())


Часовой пояс GMT +3, время: 03:36.