Can I add a function like an attribute in .setProperty?

2.7k Views Asked by At

guys. Can I use a function like an attribute in jQuery .setProperty?

jQuery(document).ready(function(){
jQuery(".content-wrapper").mouseenter(function(){
    jQuery(this).find('.separator-content-box').each(function(){
        this.style.setProperty( 'width', jQuery(jQuery('.content-wrapper').width() -  jQuery('.heading').width()), 'important' );
        this.style.setProperty( 'border-color', 'red', 'important' );
    });
});
1

There are 1 best solutions below

0
On

In futher questions please provide us the CSS and HTML pieces related to have a whole view to your case.

In jQuery i recommend to use the ´css()´ function to add inline styles to elements. Your code should be something like this:

jQuery(document).ready(function(){
  jQuery(".content-wrapper").mouseenter(function(){
      jQuery(this).find('.separator-content-box').each(function(){
          jQuery(this).css('width',(jQuery('.content-wrapper').width() -  jQuery('.heading').width()));
          jQuery(this).css('border-color','red');
      });
  });
});

I dont know your HTML/CSS structure, but there is a test i did to try: https://jsfiddle.net/97fjbp12/

Note: To do calculations you just need add ( and ) to make it working.