How do you activate the background color for paragraphs <p> when a bootstrap button is styled with CSS?

In the code snippet provided below, dynamic creation of paragraphs with changing background colors and styles is demonstrated.


One challenge faced in this script is maintaining the printed background colors for each dynamically generated paragraph. The issue arises during the printing process when bootstrap CSS removes the background color styling.

You can access the fiddle here.

An updated version of the fiddle to address this specific problem would be greatly appreciated, especially for those new to coding like myself.

Thank you!

HTML:

<div>
<div id="styles">
    <label>Color:
        <select data-property="color">
            <option disabled>Select color:</option>
            <option>red</option>
            <option>green</option>
            <option>blue</option>
        </select>
    </label>
    <label>Font-size:
        <select data-property="font-size">
            <option disabled>Select font-size:</option>
            <option>smaller</option>
            <option>10px</option>
            <option>12px</option>
            <option>14px</option>
            <option>16px</option>
            <option>18px</option>
            <option>20px</option>
            <option>larger</option>
        </select>
    </label>
    <label>Background-color:
        <select data-property="background-color">
            <option disabled>Select background-color:</option>
            <option>aqua</option>
            <option>fuchsia</option>
            <option>limegreen</option>
            <option>silver</option>
        </select>
    </label>
</div>
<div id="text_land">xzxz</div>
<textarea></textarea>
<button>Go</button>

JQuery:

$(function () {
$('button').on('click', function () {
    var v = $('#text_land + textarea').val(),
        paragraphs = '<p>' + v.split(/\n\n/).join('</p><p>') + '</p>';
    $(paragraphs).appendTo('#text_land');
});

$('select').on('change', function () {
    var targets = $('#text_land p'),
        property = this.dataset.property;

    targets.css(property, this.value);
}).prop('selectedIndex', 0);
});

Answer №1

Uncertain about what you're asking... Perhaps you can attempt to assign values from your selections to the newly created paragraph.

$('select').each(function() {
    var $this = $(this);
    paragraphs.css($this.data('property'), $this.val());
});

Check out this JSFiddle example

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

Discover the step-by-step process of retrieving an image through jQuery AJAX in Laravel 8

I'm facing an issue while trying to download images using jQuery/AJAX in Laravel 8. Although I am able to retrieve the image in the response, it isn't downloading as expected. Could someone please assist me in resolving this problem? Controller ...

Disable, Hide, or Remove Specific Options in a Single Dropdown Selection

A challenge I am facing involves creating a form with multiple select options that need to be ranked by the user from 1-8. However, I am encountering some difficulties in hiding, removing, or disabling certain select options. Below is an excerpt from my f ...

Adjust the width of menu options using jQuery

One issue I am facing is with the menu on my homepage. I would like the menu options to enlarge upon hover, and while I have achieved this effect, there is a flaw in the animation: When I move my cursor away before the animation completes, the option abru ...

Is there a way for me to connect the ajax data to Vue components?

Utilizing Jquery ajax to load data from an external API has been successful and the v-for text is also working without any issues. Vue var vm = new Vue({ el:'.inlinePoetry', data:{ PoetryList:[] }, created:function(){ var ...

Creating an illustration with HTML5 from an image

Is it possible to draw on an image by placing a canvas on top of it? I am familiar with drawing on a canvas, but I am facing an issue where clicking on the image does not trigger the canvas for drawing. How can I resolve this? This is how my HTML looks: ...

What is the best way to set all "read" values to true for the child messages within the Firebase database?

https://i.sstatic.net/oukpl.png How can I set the read property of all children of a message to true in JavaScript with a single command? I attempted using let ref = yield firebase.database().ref(groups/${groupId}/messages).update({read:true}) but it did ...

What is the best way to center a div within another div without using the margin tag?

I am struggling to find a way to center a container (div) on my webpage. I've tried various methods like using margin:auto, margin:0 auto;, margin-left:auto;, and margin-right:auto;, but none of them seem to work. Additionally, I'm unsure about ...

Strange CSS/browser storage glitch

UPDATE: JUST REALIZED THIS ISSUE IS ONLY OCCURRING ON FIREFOX, NOT CHROME ANOTHER UPDATE: Oddly enough, this problem only occurs locally. When I push it to GitHub, everything works fine. So strange. I suppose that means it's not a major issue. On my ...

Ensuring Navigation Elements Remain Aligned in a Single Line

I'm in the process of developing an interactive project that will be showcased on a touch screen. One of its key features is a fixed footer navigation. Currently, I am using floats to position the main navigation elements and within each element, ther ...

Automatically change and submit an <input> value using jQuery

I have been working on a prototype to enable users to access all the data associated with a visualization. The idea is that they would click on a specific point, triggering a modal to appear, and within that modal, a table would dynamically filter based on ...

Tips for including input text in a select option dropdown menu

Can someone guide me on adding an input text box to a select dropdown in Javascript and utilizing it as a search filter? <select class="form-control"> <option value="trans">Trans</option> <option value="fund">Fund</opt ...

The output of the http.get or http.request callback is only visible within the shell when using node.js

Just dipping my toes into node and aiming to avoid falling into the callback hell trap. I'm currently working with two files: routes.js fetch.js //routes.js var fetchController = require("../lib/mtl_fetcher/fetcher_controller"); var express = requir ...

A guide on incorporating Vue.js into a Hexo static site generator

Exploring the use of vue.js within my hexo theme has sparked my interest. Can anyone guide me on how to compile my .vue files for both development and production environments? It's worth mentioning that I intend for vue.js to operate on the client sid ...

Is there a way to extract a username from LDAP?

Can you help me understand how to dynamically retrieve a username from LDAP? In the code snippet below, I have hardcoded the username as 'smith2': $_SERVER["REMOTE_USER"] = 'smith2'; $param = $_SERVER["REMOTE_USER"] By using this appr ...

Adjusting and arranging multiple thumbnail images within a container of specific width and height

I need a user-friendly method to achieve the following. The thumbnails will not be cropped, but their container will maintain a consistent height and width. The goal is for larger images to scale down responsively within the container, while smaller image ...

Clicking on a table will toggle the checkboxes

I am facing an issue with this function that needs to work only after the page has finished loading. The problem arises due to a missing semicolon on the true line. Another requirement is that when the checkbox toggle-all is clicked as "checked", I want ...

Updating hyperlinks from dynamic php links to stable static links

I have a script that predominantly uses absolute addressing, but now I need to switch to relative addressing. The problem I'm encountering is when trying to change the links in PHP from: <link href="<?php print $theme; ?>style.css" type="tex ...

What could be causing the decreasing opacity of lines at the edge of my HTML5 canvas?

I have embarked on the journey of creating a bar graph using an HTML5 canvas. The process involves a series of lines drawn with the help of .moveTo(), .lineTo(), and .stroke(). Below is the code snippet I am using for this purpose. Although I am new to wo ...

The Django code snippet "if request.method == 'POST':" encounters an error

Greetings, I'm encountering a peculiar issue in my recent Django project. Currently, I am experimenting with the NameForm example provided in the Django Documentation on Working with Forms. On the surface, it appears to be a straightforward exercise. ...

Styling CSS to place an image in between text and background coloring

As I try to replicate a happy accident of mine, which originally occurred during my first attempt at CSS: I was just randomly adding selectors when I stumbled upon this unique layout. However, as I proceeded with rewriting the file, I failed to save the o ...