Troubleshooting the issue of executing a script following the usage of jQuery's .after

My goal is to determine the number of div elements on a page and then insert my ad codes after the second div.

It seems like using jQuery's .after method is not effective in this scenario.

<script>
 $(function() {
  var count = $('.panel-footer.clearfix').length;
  if (count >= 3) {
    $('.panel-footer.clearfix').eq(1).after(`<script async 
     src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"> . 
</script>
 <ins class="adsbygoogle"
 style="display:inline-block;width:320px;height:100px"
 data-ad-client="ca-pub-3767785488130692"
 data-ad-slot="3213073317"></ins>
 <script>
  (adsbygoogle = window.adsbygoogle || []).push({});
  </script>`);
}
});
 

Answer №1

An HTML parser interprets a portion of your text as a closing script tag, which occurs in the 7th row of this example.

Consider relocating your JavaScript code to a .js file for a more optimal solution, or separate the script tags into individual rows (such as "</scr" + "ipt>")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is the link's clickable area bigger than its corresponding image?

After countless attempts and experimenting with various solutions, I am still facing a persistent issue related to the size of the clickable area of an image linked to a video. The problem seems to be that the clickable area extends beyond the actual imag ...

Neglect to notify about the input text's value

Having trouble retrieving the text from a simple <input id="editfileFormTitleinput" type="text>. Despite my efforts, I am unable to alert the content within the input field. This is the code snippet I've attempted: $('#editfileFormTitleinp ...

What is the best way to include a background image in an Angular selector?

I'm having trouble setting a background image for an Angular selector. Here's the code I'm using: <app-highway-card [ngStyle]="{'background-image':'url(https://cdn.pixabay.com/photo/2021/09/04/09/32/road-6597404__340.j ...

Tips for integrating File Upload with an AJAX form in MVC 4

I am looking to incorporate a File Upload feature in MVC 4 that is compatible with all browsers including IE 8 or higher, Chrome, and FF. The key requirement is to have AJAX support, as I intend to integrate it within an AJAX.BeginForm. While I have foun ...

Utilizing Bootstrap 4: The Use of an anchor tag in a button element

I am facing a situation where I have an icon represented by the HTML code <a>, which acts as a link redirecting to a different page. This <a> is nested inside a collapsible button, meaning that clicking on the icon expands the menu before actua ...

Is it possible to utilize a single Promise multiple times?

// App.js sites[site_name].search(value).then(function(results) { console.log(results); }); // SearchClass.js Search.prototype.search = function(search) { var self = this; this.params['wa'] = search; return new Promise(function ...

Utilize the Math.log() function within an HTML document

I am attempting to incorporate a Math operation in an HTML page, but unfortunately it is not functioning as expected. Here is the code snippet that I have experimented with. Is there any solution to make this code operational? HTML code <div> < ...

Calculate variance between two numbers using Angular

Is there a way I can calculate the difference between two values in a table column and assign it to 'differenceInValues' variable? Any help would be appreciated. Thanks! <td scope="row"> {{change.oldValue}} </td> <td sc ...

The page becomes unresponsive once a window is closed

My process in selenium is outlined as follows: Accessing a webpage Clicking on a tab Clicking on the add button within the tab to open a window Closing the window Attempting to click on the same tab again Although I can successfully complete steps 1 to 4 ...

An option instead of using a pop-up window

Currently, I have a PHP script and a small form that allows users to upload image files. The user can access this feature by clicking on a button on the parent HTML page, which opens up a Pop Up Window. I understand that not everyone is a fan of 'Pop ...

Issues with navigation menu functionality in IE8

When I click on the navigation menu in IE8, the menus overlap with each other. This issue does not occur in other browsers. Here is the link to my site: Below is the code for the navigation menu: li id="<?php echo ($epage =='ehome') ? ' ...

Guide to navigating to a different view with Barcode-Scanner in Ionic 2

I'm struggling to redirect to a different view after scanning a barcode in my Ionic 2 app using barcode-scanner. I've tried the push method but it's not loading the other page, and passing parameters to the new view also doesn't seem to ...

Is it possible to use TypeScript in a React Native project with a JavaScript file?

Currently, I am learning React Native by working on app clones like Instagram and YouTube. I have recently started an AirBnb clone project, but I'm facing some issues with the initial build. One issue I noticed is that in 'App.js', the temp ...

Having trouble with margins not working after adding the clear property in CSS?

I recently applied clear:left to a div in my code, but when I tried adjusting the top margin, nothing seemed to change. Take a look at the snippet below: <!DOCTYPE html> <html> <head> <title>Float</title> <meta cha ...

Tips for triggering a JavaScript function within WordPress using an inline function call

While setting up my plugin in the WordPress admin area, I encountered an issue with a form that stores user information. In my file input type, there is a JavaScript function call to my custom JavaScript that I have linked. Here is the line of code causing ...

Placing an image at the forefront of all elements

Recently, I created a horizontal opt-in bar for my Newsletter on my website. Instead of the traditional submit button, I decided to use an image by incorporating some CSS: #mc_embed_signup input.button { background: url(http://urltotheimg.com/image.jpg); ...

Experience the combined power of addthis, isotope, and nicescroll - all in a single

I am utilizing a WordPress template that includes a set of share buttons from AddThis. <ul class="addthis extra"> <li class="addthis-hold"> <div class="addthis_toolbox" addthis:url="<?php the_permalink( ...

Strategies for managing grid overflow situations

Check out my codepen showcasing the current issue I'm dealing with: https://codepen.io/marcdaframe/pen/qeBWNd <div> 123 abc <div class="container"> <div class="wrapper"> <div>One</div> <div>Two</div> ...

Is there a way to modify Vue component properties using plain JavaScript code?

I am currently working on a Vue 2 project developed using Vue CLI, and my goal is to package it as a library. I want to create a wrapper script that abstracts away dependencies and Vue syntax to enable easy interaction like the examples below: // Mounting ...

Have an overlay on a specific area of the webpage while ensuring the remaining sections remain interactive to the user's inputs

Looking for a way to add an overlay in a specific area of a webpage without blocking the other sections? I attempted to use the LightBox feature from primefaces components, but it didn't give me the desired result. I'm struggling to keep the unco ...