Add new image block, set default class name and update it using Javascript

I am trying to programmatically set a default class on an image block, which is applied without the user manually adding it via the ‘Additional CSS’ field. I have tried applying a default style on image blocks, which works initially – wp.blocks.registerBlockStyle( ‘core/image’, { name: this.activeCategory, label: this.activeCategory, isDefault: true }); But after it is…

How do I render a submit button so that it’s disabled initially and enabled by JavaScript?

We have a form that includes a React JS frontend component. The component collects some required information, which the React component then supplies to the backend by populating a hidden form field. To ensure that a user cannot bypass entering the required data through the component, we need to satisfy the following requirements: Before the…

Parsing URL parameters and return javascript object with an array inside

I have the following url with params: abc?carbs=pasta,rice,noodles&sauce=tomato&wine=red As you can see, carbs is an array divided by a comma. So, by using the following code: sourceURL .slice(1) .split(‘&’) .map(p => p.split(‘=’)) .reduce((obj, pair) => { const [key, value] = pair.map(decodeURIComponent); return { …obj, [key]: value }; }, {}); I get this NOT CORRECT result:…

Can I make this media query work in my javascript?

i’m trying to get my site to know when it’s above 1096 to execute some CSS styling, here is my code var mq = window.matchMedia(‘@media all and (max-width: 1096px)’); if(mq.matches) { window.parent.document.getElementsByClassName(“sticky-leaderboard-ad-container”)[0].setAttribute(“style”,”padding-top: 4rem !important; margin-left: 0 !important”); } please can someone let me know why this isn’t working? thank you in advance edit: i can’t…

JavaScript Counter Increment [closed]

Javascript Code <script> var str_counter_1 = 0; var str_counter_2 = 0.0004*12; var display_str = “”; var display_div = document.getElementById(“display_div_id”); function incrementCount(current_count){ setInterval(function(){ while (display_div.hasChildNodes()) { display_div.removeChild(display_div.lastChild); } str_counter_1++; if (str_counter_1 != str_counter_2) { str_counter_1++; // increase next count } display_str = str_counter_1.toString(); for (var i = 0; i < display_str.length; i++) { var new_span =…