Turning align= into float in Javascript:

When creating an HTML newsletter, I am required to use the deprecated align attribute to position images. While this works well in emails, it does not have any effect in IE. Is there a way to target elements containing the align attribute and convert it to float instead? The content is generated through a CMS, so I would prefer not to ask users to manually add classes to images if possible. Thank you!

Answer №1

If you're creating HTML for a web page and not an online email client, here's how you can target all images with the align attribute and convert it to float:

$('img[align]').each(function(){

    // perform conversion
    if($(this).attr('align') == 'left')
        $(this).css('float', 'left');
    else if $(this).attr('align') == 'right')
        $(this).css('float', 'right');

    // remove old align tag
    $(this).removeAttr('align');
});

You can add more conversions as needed; I've only included left and right as examples.

We have to explicitly convert each possible value because middle, top, and bottom are not valid values for float. You may need to adjust the CSS property vertical-align instead, but that's just a suggestion.

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

Having difficulty retrieving information from a factory in AngularJS

I'm encountering an issue with my db factory where the data returned from the database is coming back as 'undefined' after successfully posting it to the client. This is how my factory function is structured: uno.factory('adbFactory&a ...

Obtaining parameter in angular 2

I am on a mission to extract the username from a URL Within app.routing, I have set up the following route: export const routes: Routes = [ { path: 'dashboard/:username', component: App } ]; In my app component, I am attempting to retriev ...

Include an edit button with each row in an HTML table for seamless editing of the database

I am currently exploring php and seeking assistance with a project for my internship. I have successfully queried all records from the mysql database and displayed them in an html table. However, I now want to include an edit button in a separate column fo ...

Instructions on transforming a XAML grid in WPF into a JSON array

Currently, I am utilizing a XAML WPF grid in my project and I am looking to transform the structure of the grid into JSON format. Do you have any suggestions or ideas on how this can be achieved? For reference, here is an example: <GridBinding> ...

Is the connection and callback order incorrect in Node.js and MQTT?

As I explore using the mqtt package for nodejs, I keep coming across code samples like the one below: const mqtt = require('mqtt') const client = mqtt.connect('mqtt://test.mosquitto.org') client.on('connect', function () { ...

Error in Typescript: Attempting to access the property 'set' of an undefined value

Currently, I am in the process of setting up a basic example of push notifications on Android using Nativescript and Typescript. Although my code may seem a bit messy, I am struggling with properly rewriting "var Observable = require("data/observable");" a ...

Calculate the dimensions of each list item and dynamically increase the size of the unordered list with jQuery

Trying to extract the 'width' style attribute from li and assign it to ul. The HTML code looks like this: <div id="carousel_team" class="glide"> <ul class="slides" style="opacity: 1; width: 1464px;"> <li class="slide first active ...

Modify Knockout applyBindings to interpret select choices as numeric values

Utilizing Knockout alongside html select / option (check out Fiddle): <select data-bind="value: Width"> <option>10</option> <option>100</option> </select> Upon invoking applyBindings, the options are interprete ...

How to stop AngularJS onClick event from causing scroll to jump to top of

As I work on developing a website using Angular JS and Bootstrap, I encountered an issue with the hamburger menu button on my homepage. Whenever I scroll halfway down the page and click the hamburger icon, it automatically scrolls me back to the top of the ...

Creating my initial navigation bar for the first time?

Today was my first day diving into the world of HTML and CSS. Instead of just reading text, I decided to learn by building something. [ http://jsfiddle.net/GUkrK/ ] I chose to create a sample navigation bar. <html> <head> <title> n ...

Switch between two AppBars simultaneously while scrolling in Material UI

In my Header.js component, I have two AppBars. The first one is sticky and the second one is not initially visible. As we scroll down, I want the second AppBar to collapse and the first one to stay stickied at the top of the screen. I looked at the Materi ...

ways to animate the closing of a dropdown menu

I'm currently working on a navbar dropdown animation code that works on hover. However, I've encountered an issue when trying to use it on a phone - I can open the dropdown, but I can't seem to close it. Does anyone have suggestions on how ...

Obtain item from JSON data structure

After querying my database, I receive a JSON object with the following structure: items = [ {"ID":1, "CODE":"code1", "DESCRIPTION":"abcd", "PRICE":100}, {"ID":2, "CODE":"code2", "DESCRIPTION":"efgh", "PRICE":100}, {"ID":3, "CODE":"code3", "DES ...

Tips for showcasing a designated set of numbers in Vue Js while iterating?

Is there a way to specifically target numbers during a loop? For example, I only want to retrieve numbers 5 and above or within a certain range that I specify. <select name="" id="input" class="form-control" v-model="selectcompetitionyear"> < ...

"Resolving a problem in an HTML form using jQuery and AJAX technology

In my HTML form, the countries in the dropdown menu are populated from a database. When a user selects a country, the city dropdown menu dynamically appears based on the selected country. If a user enters incorrect information in any field of the form (th ...

Having problems with the Save/Edit button functionality in JQuery?

I'm currently working on a day planner project for my class (check out the image below) and I'm facing some challenges in implementing an edit/save button feature. My goal is to have the button initially display "edit", and when clicked, allow us ...

Instructions for connecting my website's URL to a designated channel (button) on an external widget

My goal is to connect a channel from a third-party widget to my website through a URL link with a button. I want the channel to open directly under that specific URL. I attempted this method, but it seems to be ineffective: shareurexperience Animal "> ...

Extract objects from a nested array using a specific identifier

In order to obtain data from a nested array of objects using a specific ID, I am facing challenges. My goal is to retrieve this data so that I can utilize it in Angular Gridster 2. Although I have attempted using array.filter, I have struggled to achieve t ...

What steps can I take to ensure this grid adjusts seamlessly across different screen sizes

I'm struggling to create a responsive grid layout and I need some guidance. How can I make this grid responsive? Specifically, I want it to switch to a one-column layout when the browser size is reduced. I've attempted using media queries and var ...

After a two-second period of inactivity, the buttons on the item should trigger an action

I have a scenario in mind that I want to implement: When the user clicks on either the "Plus" or "Minus" button. If the user doesn't click on any of those buttons within 2 seconds, then we assume that the current quantity should be sent to the server ...