Issue with applying style to programmatically inserted Button in JQueryMobile

Is there a way to reapply jQueryMobile's css to a button that is inserted programmatically inside a ListView? When I hard-code the button, the styling applies correctly, but when adding it dynamically, the style is lost.

For reference, this is the code used to insert an item into the ListView:

//CODE TO ADD A JAVASCRIPT BUTTON TO THE LIST
var parent = document.getElementById("group-1");
var listItem;
listItem = document.createElement('li');
listItem.setAttribute('id',"group-1-row-0");
var inner=    "<a href=\"#\" style=\"padding-top:0px;padding-left:0px;padding-bottom:0px\">";
inner = inner + "<div class=\"customTableLayout\">";
inner = inner +       "<fieldset data-role=\"fieldcontain\" id=\"ui-softbutton\">";
inner = inner +            "<input type=\"button\" id=\"ui-softbutton\" value=\"SOFTCODED\" />";
inner = inner +       "</fieldset>";
inner = inner + "</div>";
inner = inner + "</a>";
listItem.innerHTML = inner;
parent.appendChild(listItem);

//WHEN YOU TRY TO ENABLE THIS CODE, THE DISPLAY BECOMES WEIRD
//$("#ui-softbutton").button();
//$("#ui-softbutton").button('refresh');

$(parent).listview("refresh");

To VIEW the result of this code and see the HARDCODED button in action, please visit this JFiddle link.

Answer №1

Experience it live here:

All that was needed was to add the trigger('create') method

$(parent).listview("refresh").trigger('create');

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

The internal style and script specified within the <head> section are not being rendered

Within my Joomla website using the T3 template, I inserted the following "Custom Code" just before the closing </head> tag: <style type="text/stylesheet"> div.t3-sidebar.t3-sidebar-right{ background: #F8F8F8 none repeat scroll 0% 0%; ...

What is the best way to remove the background transparency of an image?

Images are being shown inside an HTML table using PHP code : This is the code for the table : for ($i = 0; $i < $data['list']['cnt']; $i++) { $tabRows[$i][1]['width'] = "45%"; $tabRows[$i][1][&apos ...

Create multiple buttons with uniform width by adjusting padding in CSS

I recently attempted to create buttons using CSS and padding. Here is the HTML code for the buttons: <link rel="stylesheet" type="text/css" href="css/style-login.css" /> <link rel="stylesheet" type="text/css" href="css/font-awesome-4.0.3.css" /& ...

Tips for integrating jQuery styling into Angular 2

Using the farbtastic color picker, I am trying to pass the color code from jQuery to the HTML element with the property [style.backgroundColor]="color" when a button is clicked. HTML: <button ion-col full clear id="color-picker-handler" (click)="initi ...

Having trouble with the Masonry jQuery plugin - it's not functioning as expected

I've been struggling to make the masonry plugin work for hours now. I've checked my code thoroughly and there are no javascript errors present. I have followed the instructions provided, but it's still not working as expected. Here is a sni ...

Angular2 poses a strange problem with ngClass

It seems like Angular is expecting me to use single quotes for the class names even if there are no hyphens in my CSS class name. I've tried everything but Angular keeps insisting on using hyphens for this specific CSS class... it's strange, or m ...

Tips for adding a class to an SVG when clicked

I want to make an SVG change color to white when clicked and its container (icon_container) to change to blue. How can I achieve this? Below is the code snippet: state = { active: false, }; click = () => { this.setState({active: !this.state.active ...

Resizing a floated div causes the image to break out

My webpage has a container div with two floated left divs inside, positioned side by side. The right div contains a YouTube video and an image. However, when I resize the page, the video and picture flow out of the containing floated div instead of dropp ...

Display a div element with sliding animation from the left side to the right

I am trying to create a slide-in effect on a div from left to right on my webpage, but it seems to be sliding in from right to left instead. I'm unsure of what the issue might be, can someone take a look and help me figure this out? $(document).rea ...

Arrange two absolute divs side by side without overlapping each other

I have a specific layout configuration: <div id="container"> <div class="left"> 1 </div> <div class="left"> 1 </div> <div class="right"> 2 </div> </div> My goal is to stack the left divs on top ...

Creating a custom arrow design for a select input field using CSS

I'm currently developing a website (using Wordpress with a custom theme) and I want to incorporate an up/down arrow in the select input field using CSS. The HTML code I have for creating the up/down arrow in the select input field is as follows: < ...

HTML/ModX styling for selected textboxes

I am looking to enhance the style of my search-box, which is similar to the one on THIS website. While I have tried using :active, the effect only lasts for a brief moment. Currently, my code is heavily influenced by modX terms, but I will still share it h ...

Tips for concealing the edges of a scroll bar while utilizing scroll as overflow

Basically, I have a div that is positioned absolutely and has multiple children elements. This div can be scrolled horizontally to see all its content, but the scrollbar hangs off the bottom, hiding the bottom border radius. Here is the HTML code: <ul ...

Preserving the dimensions of an expandable div

Is there a way for a div to maintain its print layout while still allowing for zooming? I attempted to enable zoom functionality on a div using jQuery to adjust the height and width percentages of a specific div with the ID "page". <div style=" heigh ...

Blurring the edges of a div container

I have successfully faded the top of a div, but I am struggling to achieve the same effect for the bottom. I attempted to reverse the CSS properties used for fading the top, but it does not seem to be working as expected. HTML: <div class="container-c ...

How can I incorporate margins or adjust scaling within dompdf?

After creating a PDF using dompdf with the paper size set to A6, I am experiencing issues when trying to print it on A4 and letter paper sizes. The left and top borders are being cut off. Is there a way to generate a PDF that is compatible with A4, A6, l ...

Tips for making slanted lines using CSS

Can this image be created using CSS and/or Bootstrap 4? https://i.sstatic.net/ajzk6.png ...

Unable to calculate height properly when using the formula height: 70% + 0px

My attempt to set the height of a div element to 70% using CSS3's calc() function has been unsuccessful. While specifying viewport height (70vh) works, I specifically need the height to be 70%. .scroll-inner-container { height: -moz-calc(70vh + 0 ...

Looking for assistance in streamlining my jQuery code for bootstrap tab pane. Any takers?

Having trouble setting a specific tab as active when navigating from different links. I have found a solution, but it involves writing code for each individual tab. Can someone offer assistance in simplifying the code? <table class="nav nav-tabs"> ...

Tips for eliminating the jittery motion in an image gallery transition

I have a gallery of images that seems to be quite 'jumpy' when opening and closing the images, as demonstrated in this fiddle. Even after applying transform:translateZ(0); as suggested here, there doesn't seem to be much improvement in redu ...