I'm in need from javascript thrigger a data-action for my button. I can't see a good way to do it.
I have this button:
echo '<button type="button" class="btn btn-sm btn-secondary" id="view" data-id="'.$row_data['id'].'" data-function="view" data-action="side_overlay_toggle" data-idioma="#" title="View Info">';
echo '<i class="fa fa-eye"></i>';
echo '</button>';
I have a function to do event handler since I need to do some queries.
$('#reloadedituser').on( "click", "button", function(e) {
e.preventDefault();
let button = $(this); // the button you clicked
let id = button.data("id"); // the data-id attribute of the button
let func = button.data("function");
if(func == "view"){
e.document.getElementById("view").click();
}
});
So, the javascript reads the code, and if the data-function is "view", I would it to thrigger the data-action from that button (side_overlay_toggle). How can I achieve that? It seems that .click doesn't make it thrigger the button. Any suggestion in this?
Also, can someone help me, before the data-action, make a query and add it to a specific div? My problem is not doing the query itself but how to handle it in javascript. Thanks.