#jquery
Вопрос:
Вторая часть инструкции attr() -> margin-top завершается с ошибкой:
var hoeheDrBoxPA = (jQuery(".header-a-p").outerHeight()/2);
var hoeheDrBoxHPA = (jQuery(".text-h-a-p").outerHeight()/2);
var hoeheDrBoxPAML = (jQuery(".header-a-p").css("marginLeft"));
jQuery(".et_pb_section_1.header-element").attr('style', 'margin-left:' hoeheDrBoxPAML '!important', 'margin-top:' (hoeheDrBoxPA-hoeheDrBoxHPA) 'px');
Работает одна инструкция:
jQuery(".et_pb_section_1.header-element").attr('style', 'margin-left:' hoeheDrBoxPAML '!important');
jQuery(".et_pb_section_1.header-element").attr('style', 'margin-top:' (hoeheDrBoxPA-hoeheDrBoxHPA) 'px');
Вступает в силу первая часть инструкции attr() -> margin-left
Что здесь не так?
Комментарии:
1. Вы перезаписываете атрибут style во второй раз.
2. Используйте .css()
Ответ №1:
Третьего параметра для attr()
:
jQuery(".et_pb_section_1.header-element").attr('style', 'margin-left:' hoeheDrBoxPAML '!important; margin-top:' (hoeheDrBoxPA-hoeheDrBoxHPA) 'px');
Поместите все это во второй параметр.
Комментарии:
1. Да, конечно, идеально!