Enhancing jQuery Mobile listview with voting buttons on each item row

I am looking to incorporate 2 vote buttons within a jQuery mobile listview, positioned on the left-hand side and centered within each list item. While I have managed to achieve this using javascript, my goal is to accomplish it without any additional scripting by leveraging standard jquery mobile data-role attributes and pure HTML & CSS.

Below is the desired HTML markup:

<div data-role="page">
    <div data-role="content">
        <ul class="has-vote-btns" data-role="listview">
            <li>
                <a href="#">
                    <h3>Line Item</h3>
                    <p>Sub title</p>
                </a>
                <a href="#" data-icon="bars"></a>
                <a href="#" class="vote-btn like-btn" data-icon="arrow-u" title="Like"></a>
                <a href="#" class="vote-btn dislike-btn" data-icon="arrow-d" title="Dislike"></a>
            </li>
        </ul>
    </div>
</div>

The accompanying CSS styles are as follows:

.vote-btn {
    position: absolute;
    top: 50%;
    left: 5px;
    z-index: 2;
}
.vote-btn .ui-btn-inner {
    padding: 0;
}
.like-btn {
    margin-top: -30px;
}
.dislike-btn {
    margin-top: 0px;
}
.has-vote-btns .ui-link-inherit {
    padding-left: 40px !important;
}
.has-vote-btns .ui-li-has-thumb .ui-link-inherit {
    padding-left: 118px !important;
}

Despite these efforts, the functionality does not work as intended (live example).

To address this issue, I resorted to dynamically adding the vote buttons through javascript after the listview has been enhanced. The script that successfully accomplishes this can be viewed in action here (live example):

$(function(){
    $('.has-vote-btns').each(function() {
        $(this).find('li').each(function(i, li){
            $('<a href="#" class="vote-btn like-btn" title="Like"></a>').buttonMarkup({
                icon: 'arrow-u',
                iconpos: 'notext'
            }).appendTo(li);
            $('<a href="#" class="vote-btn dislike-btn" title="Dislike"></a>').buttonMarkup({
                icon: 'arrow-d',
                iconpos: 'notext'
            }).appendTo(li);
        });
    });
});

However, this post-enhancement addition of the vote buttons via javascript is not the optimal solution. Ideally, I seek a method that forgoes javascript altogether in inserting these buttons and relies solely on HTML and CSS. Is there a viable approach that achieves this objective?

Answer №1

I have enhanced your initial fiddle using only CSS for a solution:

FIDDLE

While there are other approaches, I think this resolves the issue.

The HTML for the <ul> is updated as follows:

<ul class="has-vote-btns" data-role="listview" data-split-icon="bars" data-split-theme="d">
    <li> 
        <a href="#">
            <h3>Line Item 1</h3>
            <p>Sub title 1</p>
        </a>
        <a href="#"></a>
        <div class="vote-btns"> 
            <a href="#" data-role="button" data-icon="arrow-u" data-icon="arrow-u" data-iconpos="notext" data-inline="true" title="Like"></a>
            <a href="#" data-role="button" data-icon="arrow-d" data-icon="arrow-u" data-iconpos="notext" data-inline="true" title="Dislike"></a>
        </div>
    </li>
</ul>

The data split icon and theme are now set at the <ul> level (

data-split-icon="bars" data-split-theme="d"
), with the voting buttons placed in their own container within the <li> to allow for positioning on the left. Below is the CSS that handles the position of the container and the two buttons inside:

.has-vote-btns .ui-link-inherit {
    margin-left: 40px !important;
}
.vote-btns {
    position: absolute;
    top: 0px;
    width: 39px;
    bottom: 0px;
}
.vote-btns a:first-child {
    position: absolute;
    bottom: 50%;
    margin-bottom: 2px;
}
.vote-btns a:last-child {
    position: absolute;
    top: 50%;
    margin-top: 2px;
}

You can utilize your own like-btn and dislike-btn classes instead of the :first-child and :last-child pseudo selectors if preferred...

For jQM 1.4.x, here is an updated FIDDLE

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

Troubleshooting AngularJS POST Request Error with Request Body

I am a beginner in AngularJs and I am trying to make a post request to a server with enum form. Currently, I have the following JavaScript code: function completeTaskAction2($scope, $http, Base64) { $http.defaults.headers.common['Authorization'] ...

Can we keep a portion of the input placeholder content?

The input box below accepts values in percentage form. To indicate this, I have set a placeholder that says Percentage (%). https://i.sstatic.net/LJ1ee.png My goal is to automatically add a % symbol to the value as soon as it is entered into the input fi ...

Remove the space gap between the header and card in Bootstrap

I'm in the process of creating a sleek landing/login page for my web application using Bootstrap. The current layout includes a header with text and an image, followed by a login form within a card. Looking at the image provided, it's clear that ...

I'm stumped trying to understand why I keep getting this syntax error. Any thoughts on how to fix it?

Our team is currently working on creating a dynamic SELECT box with autocomplete functionality, inspired by the Standard Select found at this link: We encountered an issue where the SELECT box was not populating as expected. After further investigation, ...

Utilizing jQuery to effortlessly generate parent and child elements in a single function call

Is it possible to create multiple elements with the same function? Currently, I am able to split a number of list items like this: <ul class="dropdown-menu"> <li>Stuff</li> <li>Stuff</li> <li>Stuff</li> ...

HTML popup window for a Socket.IO chat experience

When creating a Socket.IO chat with a generated popup window for private messages, I encountered an issue with IE9 not starting the window.opener.socket.on(...) function successfully. In contrast, Firefox and Chrome ran this function without any problems ...

Listening on TCP port for HTML5 Websocket communications

I have a desktop application that is communicating with my asp.net mvc app. The desktop application publishes data on port:10000 which I need to be able to listen to in the browser. Below is the code snippet: <html> <head> <s ...

Translating coordinates into their corresponding location on the chart

I'm currently working with a dataset containing information about an area in Western Europe. I am trying to convert coordinates into values within this table, facing a challenge similar to the one described in this query. However, I lack experience in ...

Troubleshooting Angularjs: Why isn't the HTML displaying the variable value?

Trying to display the value of an AngularJS variable in HTML using this code: <div ng-controller="MyTextbox"> <p>Last update date: {{nodeID1}} </p> Here's my angularjs controller code: angular.module("umbraco").controller("MyTex ...

Ways to specify the encoding for a text iframe embedded in a webpage

Can anyone help me with document embedding in HTML? In my current project, I am directly embedding my update logs as text files into the webpage, along with a selection menu to view all the updates. However, I ran into a minor issue where the Firefox cons ...

Using services in Angular 6 CLI with dynamically added components

One of my recent projects involved creating a directive in Angular 6 called 'DeleteDirective' and integrating it with a service called 'DeleteService' to enable the deletion of items from the application. Once an item is deleted (handle ...

Using jQuery to enclose specific words within <strong> tags

My goal is to utilize jQuery in order to locate all occurrences of the term "contracting" and enclose it within the <strong> element. Does anyone know if there is a method to accomplish this task using jQuery? Ultimately, I am seeking an output li ...

I'm encountering an error when trying to use makeStyles

Something seems off with MUI. I was working on my project yesterday and makeStyles was functioning properly, but now it's suddenly stopped working. I'm encountering an error when calling it here: I suspect the issue lies in the import statement ...

The AutoComplete component in React Material UI does not automatically assign the initialValue

I've encountered an issue with my form.js component. In this component, I have two states: update and create. Within the component, there's an AutoComplete component that works perfectly fine in the create state (data creation works as intended). ...

Struggling with design issues while implementing ajax

I'm currently utilizing JQuery and AJAX to handle the submission and processing of a form. Whenever the user clicks on the like button, the information is sent via AJAX to my like.php file for processing. The like.php file processes the request and ge ...

Learn how to personalize your Material UI icon by incorporating a plus symbol

Is it possible to add a plus sign to material ui icons? I currently have the following icon: import ApartmentIcon from '@mui/icons-material/Apartment'; I would like to add a plus sign to this icon, similar to this example: I have attempted to ...

Transferring Information Between Vue Components

In my project, I have implemented 3 Vue components to work together seamlessly. Component A is responsible for listening to an event triggered by a user clicking on HTML text and storing the data into a variable. Component B utilizes this data to make an A ...

Techniques for slowing down the propagation of events with jQuery

Is there a way to show a note after a user submits a form but before they leave the page? Here is an example of what I'm currently using: $('form').submit(function(event) { $('.note').show(); setTimeout(function() { ...

Confusion about the unwinding of the call stack in the Graph Depth-

Issue with function: hasPathDFSBroken Fix implemented in: hasPathDFS The updated version includes a forced parameter to address the issue, which I would prefer to avoid. I'm trying to comprehend why in the broken version, when the call stack unwinds ...

Using Ruby instead of Javascript in lessc

My CSS is compiled in a node application using lessc. LESS was installed via NPM. When I check the current version of lessc --version it shows lessc 1.3.3 (LESS Compiler) [Ruby] 2.3.2 How can I change it to display lessc 1.3.0 (LESS Compiler) ...