Incorporating an image as a clickable element instead of a traditional button using HTML and

Here's the issue at hand: I currently have "+" and "-" icons at the end of each row to add and delete rows as needed.

However, I would like to replace the "-" icon with a trashcan symbol instead. I attempted to do this by replacing it with an image source, but this caused alignment issues.

If we remove the box from the "+" sign and only keep the "+" for adding rows, while using a trashcan icon for deletion ("-"), that would be ideal. Can anyone assist me in achieving this? See code below.

 <tr>
                <td align="left">
                <g:select name="standard[]" id="standard" class="statSele valid" from="${standardList}" value="" noSelection="['':'Select Regulatory Standard...']"/>
                <g:select name="standard_version[]" id="standard_version" class="statSele valid" from="${standardversion}" value="" noSelection="['':'Select Version...']" style="width:150px !important;"/>
                <g:select name="standard_domainnumbers[]" id="standard_domainnumbers" req="false" class="statSeledomain valid" from="${['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50']}" value="" noSelection="['':'Select Domain...']"/>
                <INPUT type="checkbox" name="chk" class="delCheck"/>
                <input type="button" value=" + " title="Add More" class="clone-faculty"/>
                <input type="button" value=" - " title="Remove selected Row" class="remove-faculty"/>
                </td>
            </tr>


    <script>
         $('.clone-faculty').click(function() {  
            var clone = $('.add-child:first').clone(true).appendTo('#itemRows');        
            });

         $(".remove-faculty").click(function(e) {

             if($('.add-child').length > 1)
             {
                 if($(".delCheck:checked").length != $('.add-child').length)
                 {
                  $(".delCheck:checked").closest("table").remove();
                  // $(".add-child").last().remove();
                 }
                 else
                 {
                     alert('You cannot delete all rows.');
                 }
             }
          });
        </script>

Answer №1

Here is my solution:

<td align="left">
        <g:select name="standard[]" id="standard" class="statSele valid" from="${standardList}" value="" noSelection="['':'Select Regulatory Standard...']" />
        <g:select name="standard_version[]" id="standard_version" class="statSele valid" from="${standardversion}" value="" noSelection="['':'Select Version...']" style="width:150px !important;" />
        <g:select name="standard_domainnumbers[]" id="standard_domainnumbers" req="false" class="statSeledomain valid" from="${['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50']}" value="" noSelection="['':'Select Domain...']" />
        <INPUT type="checkbox" name="chk" class="delCheck" />
        <input type="button" value=" + " title="Add More" class="clone-faculty" />

        <img src="https://cdn2.iconfinder.com/data/icons/windows-8-metro-style/128/trash.png" style="width:17px;vertical-align: middle;" title="Remove selected Row" class="remove-faculty">
    </td>

Check out the JSFiddle for a visual representation

Answer №2

give this a shot:

<tr>
                <td align="left">
                <g:select name="standard[]" id="standard" class="statSele valid" from="${standardList}" value="" noSelection="['':'Select Regulatory Standard...']"/>
                <g:select name="standard_version[]" id="standard_version" class="statSele valid" from="${standardversion}" value="" noSelection="['':'Select Version...']" style="width:150px !important;"/>
                <g:select name="standard_domainnumbers[]" id="standard_domainnumbers" req="false" class="statSeledomain valid" from="${['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50']}" value="" noSelection="['':'Select Domain...']"/>
                <INPUT type="checkbox" name="chk" class="delCheck"/>

                <span class="glyphicon glyphicon-add" ng-click=""></span>

                <span  class="glyphicon glyphicon-trash" ng-click=""></span>
                </td>
            </tr>

Answer №3

<img src=" + src " width="what size you want" title="Add More" class="clone-faculty"/>
<img src=" - src" width="what size you want" title="Remove selected Row" class="remove-faculty"/> 

the above code replaces the following

<input type="button" value=" + " title="Add More" class="clone-faculty"/>
<input type="button" value=" - " title="Remove selected Row" class="remove-faculty"/>

it is important not to declare a height value once the width attribute is declared in order to maintain the image ratio

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

Bringing in a selection of functions as an object using ES6 imports

functions.js export const setA = () => {...} export const setB = () => {...} export const setC = () => {...} component.js import {setA, setB, setC} from 'functions' export class componentOne extends React.Component { constructor(p ...

"The issue arises when attempting to use Ajax to call a PHP script

Here is the jQuery script I am working with: <script> $(document).ready(function(){ $("#username").blur(function() { //remove all the class add the messagebox classes and start fading $("#msgbox").removeClass().addClass('messagebox&ap ...

Angular & Loopback: The function User.login is not recognized

Today, I encountered an error while attempting to execute the Login function in Ionic. An error message popped up stating: TypeError: User.login is not a function (found in controller.js). Here's a snippet from my controller.js : angular.module(&ap ...

Enhance jQuery for a dynamic navigation dropdown with multiple sub-menus

Looking for help with a jQuery script as I am a beginner in using jQuery. jQuery(document).ready(function ($) { $(".sub-menu").hide(); $(".current_page_item .sub-menu").slideDown(200);; $("li.menu-item").click(function () { if ($('.sub-menu&apos ...

When looking at the table, it will only read integer values for EmpID. However, if it is a string value

This method on a website uses AJAX and jQuery. When the EmpID is in the format of 123, 12, or 123456, it opens a popup box and displays the desired output. However, when the EmpID is in the format of A001 or ABC, it displays an error message saying "Error ...

The CSS grid-template-areas feature is not performing as anticipated

.content { width: 600px; height: 600px; border: 4px solid lime; display: grid; grid-template-areas: 'a d' 'b d' 'c d'; } textarea, iframe { margin: 0; box-sizing: border-box; } .content > .a {gri ...

Guide on sending an AJAX request in jQuery to PHP while another request is still being processed

I am currently working on a feature that requires the use of HTML, jQuery, PHP, C++, and MySQL. The process involves making an AJAX call from PHP to C++ (via protocols) for server installation, which will take some time to complete. During this time, I ne ...

Is it possible to extract elements from a single list and insert them onto various pages?

Currently, I am retrieving items from a list using an ajax call. After constructing the HTML content, I insert these items onto a page. Now, I want to extract the same items and display them on another page with a different style. Is there a method to conn ...

What is the best method to fill a mat-select dropdown with an existing value?

I am encountering an issue with a mat-form-field that contains a dropdown of data fetched from an API. I can successfully select an option and save it to the form. However, upon returning to the dropdown or reloading the page, the saved value does not appe ...

What is the best way to activate matching dates within the rangeselector data?

A datepicker has been integrated into a highchart in the following manner. $(function() { $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) { // Create the chart $('#co ...

An advanced view engine capable of handling both ajax requests and direct function calls

In Node.js (Express), I am seeking a method to present a template in two different ways: one normally as HTML and the other as JSON, specifically for Ajax requests. Assume I have a swig template structured like this: {% extends 'layout.html' %} ...

What is preventing jQuery UI from detecting jQuery?

I have successfully created a JavaScript widget that is capable of being embedded on any third-party website, in any environment. The widget relies on jQuery and jQuery UI for its functionality. After following the guidelines outlined in How to embed Javas ...

Utilizing Python Selenium to Interact with Buttons

Encountering an issue while trying to use Selenium to click on a tab or button within my web application. Below are the code snippet and CSS selectors: Error message: selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: #t ...

Transmit intricate data structure to a web API endpoint using AJAX requests

When attempting to send a complex object named vm containing an object 'Budget' and an array 'BudgetDetails' populated with rows from an HTML table to my API controller using AJAX, I encounter the error message "Uncaught RangeError: Max ...

Error: The property 'fixtures' of an undefined object cannot be accessed. This issue arose from trying to access nested JSON data after making

Struggling with asynchronous calls, JS, or React? Here's my current challenge... Currently, I am using the fetch library to display a table based on data structured like this (note that there are multiple fixtures within the fixtures array): { " ...

Tips for implementing ng-hide/ng-show animations

Is there a way to create an animation on an element in Angular that will be triggered when the item's visibility is changed using ng-hide/ng-show? Which specific CSS classes should be included to ensure smooth animations on elements? ...

Guide to retrieve the Last-Modified date using Javascript

It is common knowledge that the document.lastModified function returns a string containing the date and time when the current document was last modified. Is it possible to obtain the Last-Modified for a script? Here is an example of HTML code: ... <s ...

How can the Flickr API be utilized with JavaScript functions?

In preparation for a project, we are required to utilize the Flickr API in order to display a collection of photos when a specific category is selected. I have successfully set up my categories on the left side of a flexbox container. However, I am struggl ...

Having trouble connecting the controller variable in AngularJS to the HTML page

I'm struggling with a simple query that doesn't seem to be working for me. When making an Ajax call and retrieving data from the backend, everything seems to be in order. Here's the code snippet: $.ajax({ type: "GET", url: service ...

Pass function A as a prop, then trigger a different function when the child function calls A

Apologies for the uninformative title; I struggled to come up with a suitable one regarding my issue. I have a question concerning React code. My Child component receives the onValueChanged function as a prop. This function was initially passed down to th ...