For example, I have some selector:
$(".external_network_id").each(function(){ console.log($(this).css('margin')); }); I can change his styles with the .css method. But if I pass it on to some function
$(".external_network_id").each(function(){ myfunc($(this)); }); Where
function myfunc(object){ console.log(object.style.margin); //сработает корректно console.log(object.css('margin')); //выведет ошибку } then I will not be able to use jQuery methods and will have to be content with javascript. What transformations can I do to work with jQuery inside a function?
I will add an example from the project, the previous error occurs in the line console.log(object.style.margin); Here is the code:
$("body .equipment").each(function(){ findNetwork($(this)); }); function findNetwork(object){ var id_list = object.find(".network_id"); $(".room").find(".network .network_id").each(function(){ var net_in_room = $(this); $.each(id_list, function(index, id){ if (net_in_room.text() == id.textContent){ setRoom(net_in_room.closest(".room"), id.closest(".equipment")); } }); }); function setRoom(room, object){ var obj_y = Number(object.style.marginLeft.slice(0, -2)); var obj_x = Number(object.style.marginTop.slice(0, -2)); //при попытке использовать .css("margin-left") вместо style.marginTop.slice происходит ошибка. var obj_width = object.width(); //ошибка происходит конкретно в этой строке var obj_height = object.height(); }
console.log(object.style.margin)since the jQuery object does not have astyleproperty. The only option why this might work is that the html element is passed to the function. that is, the call is notmyfunc($(this)), butmyfunc(this)is Grundy