I'm creating a simple chrome extension. I want to apply some style rules when a certain element is present on the DOM. After an inspection of the website where I want to apply that modification, I saw that the interested element is created only on certain pages and isn't present anywhere on the site. How I can apply these rules using jquery? Here is the code I'm testing but without success:
(function($){ $(document).ready(function(){ var el = $('.e-overlay--adblock'); if(el.length){ el.css({'opacity':'0'}); console.log('Extension Started!'); } }); }(jQuery)); I've also tried with this solution but without success:
I think that the problem is also with the class of the element that is .e-overlay .e-overlay__modal .e-overlay--full .e-overlay--adblock
$(document).ready(function(){ var el = $('.e-overlay')[0]; // Create an observer instance linked to the callback function var observer = new MutationObserver(function(){ el.css({'opacity':'0'}); console.log('Extension Started!'); }); // Start observing the target node for configured mutations observer.observe(el, config); // Later, you can stop observing observer.disconnect(); }); the mutation observer will give me this error:
Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.
configdeclared? Does$('.e-overlay')select more than one element? Please add more information to your question including and example of the HTML so we can see exactly what you are attempting here. Does the target element include ALL of those classes at the same time? Does the element exist upon initial render or is it dynamic and created later thus require something likeMutationObserverhere?