Ways to eliminate line breaks in a specific script

I am brand new to using phonegap and I need some help figuring things out.

Here is the script source:

<script src="http://www.transfermate.com/en/exchange_rates_api.asp"></script>

I am attempting to remove the
s in the div 'currency_converter_calculator_subscribe_form_under_info.'

This is what I have tried so far:

$('#currency_converter_calculator_subscribe_form_under_info.form_under_info calculator_subscribe_form_under_info br').remove();

EDIT The issue is that the script generates a string like this:

4 USD United States of America Dollars
=
3.1308 EUR Euro

To reduce the space taken up by the line, I either need to eliminate the
s or shorten the string. I know that after the number, there will always be a 3-character acronym such as USD, EUR. Another option would be to extract the part of the string between this character code and before the = sign, but I am struggling with referencing the label properly:

$('#currency_converter_calculator_subscribe_form_under_info').val('testing');

The ideal solution would be:

4 USD = 3.1308 EUR

Any assistance would be greatly appreciated.

Answer №1

function eliminateBreaks(container) {
  var breaks = container.getElementsByTagName("br");
  for (var i = 0; i < breaks.length; i++) { breaks[i].parentNode.removeChild(breaks[i]); }
}

where container represents the ID of your chosen container

var container = document.getElementById('currency_converter_calculator_subscribe_form_under_info');
    eliminateBreaks(container);

Does this method suit your needs?

If you prefer not to create an additional function, you could utilize CSS to hide the
tags by adding the following code to your stylesheet: br { display: none; } or

#currency_converter_calculator_subscribe_form_under_info br { display: none; }
for targeted application within a specific container.

Alternatively, you can perform a regex replacement on your string:

var str = "4 USD<br> = <br>3.1308 EUR";
var newStr = str.replace(/<br\s*[\/]?>/gi, " ");

Or using jQuery:

var str = "4 USD<br> = <br>3.1308 EUR";
var regex = /<br\s*[\/]?>/gi;
$("#mydiv").html(str.replace(regex, " "));

Answer №2

Remove all br tags in a specific div by using the find() method

$(document).ready(function() {
  
  $('.currency_converter_calculator_subscribe_form_under_info').find('br').remove();

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>


<div class="currency_converter_calculator_subscribe_form_under_info">

  Lorem ipsum dolor sit amet,
  <br/>consectetur adipisicing elit.
  <br/>Obcaecati quos tenetur dolorum doloribus rerum
  <br/>ex ab dignissimos adipisci esse
  <br/>consequuntur facilis ipsam numquam
  <br/>officia officiis sit rem sint
  <br/>eligendi laudantium.
</div>

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

Overlap in Bootstrap 4 Sections

I'm facing an issue with two sections on my website. They are properly separated until a certain size, https://i.sstatic.net/e52t2.png, but when the size is reduced, they start to overlap https://i.sstatic.net/aMtHr.png. Below is a snippet of my code: ...

Ensuring jQuery ajax requests can still be made when clicking on various links

After successfully creating code for ajax requests and fetching information from the server, I encountered an issue where clicking a link would smoothly transition me to a new page without refreshing the header and footer. However, upon clicking another li ...

What is the best way to prevent text from being dragged within a contenteditable div?

Currently, I am working on a contenteditable div. This div has a default behavior that allows you to drag pieces of text around. I have tested this behavior on Chrome/Windows only so far. https://i.sstatic.net/IWLsY.gif I am looking for a way to disable ...

Error parsing XML: Missing opening tag

function fetchUserDetails() { $url = "http://steamcommunity.com/profiles/{$this->steamID64}/?xml=1"; $xmlData = simplexml_load_string($url); if(!empty($xmlData->error)) { return NULL; } $this->displayName = (string) $xmlData-&g ...

Using jQuery Ajax and PHP to retrieve data from a database based on multiple checkboxes

my code currently only selects one checkbox at a time. What I am trying to achieve is when clicking on the first checkbox, it should display a result. Then, if the second or third checkbox is clicked, all checkboxes should be submitted together to the proc ...

Choosing a class using CSS

Can someone please help me with editing this HTML code using CSS? I'm trying to target the coupon divs using #coupon but it doesn't seem to be working. Any assistance would be greatly appreciated. <div class="coupon"> <h1>Classic ...

Incorporate a dropdown menu based on the selection made in another dropdown menu

I have a scenario on my website where I want to dynamically add select boxes based on the value selected in the previous one. Here is the code snippet: <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js"> </script> & ...

Why Isn't This JPG Image Functioning Properly in HTML/CSS?

I am facing an issue with a JPG image that I am attempting to use in CSS as a background-image for a div container. For some reason, this particular image refuses to render in the viewport. Interestingly, when I inspect the element, I can see its thumbnail ...

Trouble arises when trying to combine NextJs 12.2.5 with next-auth 4.17 due to a dependency

npm ERROR! Could not find a solution for the dependency: npm ERROR! required peer next@"^12.2.5 || ^13" by [email protected] npm ERROR! in node_modules/next-auth npm ERROR! next-auth version is "*" as defined in the root project ...

Enhance the jQueryUI progress bar by dynamically updating it with inner HTML data

I am working on implementing a jQueryUI progress bar and facing some challenges. Here is the basic code for the progress bar: <script> $(function() { $("#progressbar").progressbar({ value: 50, }); }); </script& ...

I am attempting to separate this "for" loop in order to generate five distinct DIV elements

Hello there! I am a beginner and I am attempting to create 5 different players by using some code that I found. Here is the code I have been working with: https://codepen.io/katzkode/pen/ZbxYYG My goal is to divide the loop below into 5 separate divs for ...

An error was encountered: Unable to assign value to the property "once" of [object Object] because it only has a

`Encountering an Uncaught TypeError: Cannot set property 'once' of [object Object] which has only a getter at HTMLDivElement.addEventListener (polyfills.js:1:146664). This issue is being faced during the process of upgrading the Angular version. ...

What are the best practices for utilizing createHash('sha1') effectively in node.js?

Exploring the intricacies of a login system using React, MySQL, and Node.JS has been an interesting journey. Here's a glimpse of what I've accomplished so far: Presenting my router setup: const express = require('express') const app = ...

What is the method for updating the current page as you scroll down, with a specific number of pixels remaining until reaching the

Is there a way to update the current page on scroll down with a specified number of pixels remaining until the end of the page? We are all familiar with the functionality seen on Facebook, where once you log in, you can see a certain number of records as ...

Why am I experiencing a problem with my ajax call only working once when I submit forms that are rendered with @Html.Render

I have a scenario where my index page loads with two partial views, each containing an ajax call that filters content based on date. The issue I'm facing is that the ajax call only works once successfully, and subsequent attempts cause a full page ref ...

Expanding the canvas leads to the freezing of the Ionic app on the emulator

I'm currently working on developing an ionic app that includes the feature of allowing users to sign their name on a canvas. I am utilizing signature-pad.js from https://github.com/szimek/signature_pad to create this signature functionality. Everythi ...

I prefer the user not engage with the background when the jQuery dialog is displayed

When a user clicks on an external link, the jQuery UI dialog box will appear with "ok" and "cancel" buttons. Upon clicking "ok," the user should be directed to the external site. Although everything is functioning correctly, there is an issue with the mod ...

Encountering a CORS issue specifically on the client side of a Next.js application when interacting with an API gateway

I've been struggling with this issue for a week now and can't seem to fully describe it. I have a FastAPI server running as a Lambda connected to API Gateway. https://i.stack.imgur.com/S5Zx9.png Both FastAPI and API Gateway have CORS enabled, b ...

The contents of the image are currently unable to be viewed

I have a Blob of an image that I am trying to display in the browser. However, when I use the code below to open the image, it shows some Mandarin scripts on the window. Here is the code snippet: var url="http://....link..../downloadFile?fdsFileId="+file ...

What is the most effective way to switch between content in tabs using Bootstrap 5?

Can content in Bootstrap 5 tabs be toggled to close all tabs when clicking on an already open tab? Bootstrap documentation <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="62000d0d ...