I know that it is possible to use on()
and delegate the selector, so it accesses the dynamic element from a static element, but if you can not use on()
, what to do?
For example, within any function I need to get the id of a dynamically added element to change a style attribute and there is no event that triggers the on()
:
jQuery
function(){
if(1 + 1 == 2){
//Não vejo como usar o on() nessa situação.
$("#elemento").css("color", "black");
}
//Talvez...
$("#elemento2").on((1 + 1 == 2), "#elemento", function(){
$("#elemento").css("color", "black");
});
}
Is there any other method, such as generating actions that are independent of other user actions or is it impossible to do this with jQuery?