JQuery Powered Text Analyzer

Our team is in the process of developing a text analyzer tool to review emails before sending them out. The goal is to involve all team members in selecting the best emails to send to clients:

Implemented the following HTML code:

  <p class="sentence" href="#">Lorem ipsum dolor, adipisicing elit.</p>
  <div class="popup-inner" data-popup="popup-1" hidden="hidden">
       <input type="radio" name="gender" value="like" checked> Like<br>
       <input type="radio" name="gender" value="dislike"> Dislike<br>
       <input type="radio" name="gender" value="other"> Other
       <a class="popup-close" data-popup-close="popup-1" href="#">x</a>
  </div>

Code used to execute it:

var sentence = $('.sentence').html().split(/\s+/),
    result = [];

for( var i = 0; i < sentence.length; i++ ) {
    result[i] = '<span class="keyword-btn" data-popup="' + i + '">' + sentence[i] + '</span>';
}

$('.sentence').html(result.join(' '));

$('.sentence').on('click', 'span', function(){
    $(this).addClass('highlight');
});

function showPopup(span, $popup) {
  var offset = span.offset();
  $popup
    .fadeIn(350)
    .css({
      left: Math.min(offset.left, $(window).innerWidth()-$('.questions').outerWidth()) + 25,
      top: offset.top + 50
    });
}

$(function() {
    //----- OPEN
    $('span.keyword-btn').on('click', function(e)  {
        //var targeted_popup_class = jQuery(this).attr('data-popup-open');
        //$('[data-popup="' + targeted_popup_class + '"]').fadeIn(350);
         showPopup($(this), $('div.popup-inner'));
        e.preventDefault();
    });

    //----- CLOSE
    $('[data-popup-close]').on('click', function(e)  {
        var targeted_popup_class = jQuery(this).attr('data-popup-close');
        $('[data-popup="' + targeted_popup_class + '"]').fadeOut(350);

        e.preventDefault();
    });
});

Added CSS styling:

.sentence span:hover, .highlight{
    color: rgb(58, 207, 222);
    cursor: pointer;
}
/* Close Button */
.popup-close {
    width:30px;
    height:30px;
    padding-top:4px;
    display:inline-block;
    position:absolute;
    top:0px;
    right:5px;
    transition:ease 0.25s all;
    -webkit-transform:translate(50%, -50%);
    transform:translate(50%, -50%);
    border-radius:1000px;
    background:rgba(0,0,0,0.8);
    font-family:Arial, Sans-Serif;
    font-size:20px;
    text-align:center;
    line-height:100%;
    color:#fff;
}

.popup-close:hover {
    -webkit-transform:translate(50%, -50%) rotate(180deg);
    transform:translate(50%, -50%) rotate(180deg);
    background:rgba(0,0,0,1);
    text-decoration:none;
}

Struggling to display radio buttons below selected words. Any assistance would be appreciated.

Answer №1

One thing you may have overlooked is adding a position attribute for .popup-inner

.popup-inner {
    width:100px;
    height:50px;
    padding:10px;
    position:absolute;
    top:50%;
    left:50%;
    -webkit-transform:translate(-50%, -50%);
    transform:translate(-50%, -50%);
    box-shadow:0px 2px 6px rgba(0,0,0,1);
    border-radius:3px;
    background:#c1cecb;
}

By including this in your code, the button box should appear beneath each selected word.

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

Issue with opening mobile app from deep link in HTML email

My HTML form contains a deeplink that is submitted through the SendGrid API on nodeJS. After sending the email, users can view it but are unable to click on the deeplink. <!DOCTYPE html> <html> <head> ...

Issue with JQuery form submission causing controller method not to be executed

I am facing an issue with two click methods in my JavaScript code. Method 1 is successfully hitting the controller method, but when I try to trigger Method 2 by clicking on a button, it does not seem to call the controller. I have tried various solutions ...

Assign the jQuery library to a variable

I've been attempting to load a script tag via ajax, and one way to achieve this is by appending it using the .html function in jQuery. Here's an example of what I tried: jQuery(document).ready(function($) { var flexsliderThumg = "jQuery(doc ...

How to disable form submission using ENTER key in jQuery when alerts are present?

My form contains a text input field. To prevent the form from being submitted when ENTER key is pressed, I used this code snippet: jQuery("#inputTags").keydown(function(event) { if (event.keyCode == '13') { event.preventDefault() ...

Having trouble displaying information in JavaScript after using getScript() to retrieve data from an API containing a JSON block database

I'm a newcomer to the world of Ajax/json/jquery and I find myself with a few inquiries. Currently, I am working with an API located at which contains a JSON block that looks something like this [{"id":"1","FirstName":"Micheal","LastName":"Kooling"}, ...

When the width of the window is hidden, conceal

My webpage has a carousel with pictures, but on smaller devices, they do not appear properly. I am now trying to figure out how to hide the div if the width is less than 1015px. Here is the code for my div: <html> <body> <div id="myCarou ...

How can I achieve transparency for an element while it is nested within multiple parent

Is there a clever method to achieve transparency for an element that allows the background of its parent element to shine through and display the body background, for example? Consider this scenario: <body style="background: url(space.jpg)"> <di ...

Display an HTML tag with JavaScript

My code is in both HTML and TS files. The content stored in the Description variable looks like this: <div>aaaa</div><div>bbbb</div><div>cccc</div> Currently, the output displays as follows: aaaabbbbcccc I want to modi ...

unselect the button using jQuery

I want to trigger a popover when a variable exceeds a certain value, triggered by clicking a button: $(function () { $('[data-toggle="tooltip"]').tooltip({ trigger: 'manual', placement: 'top', titl ...

Utilize grids to ensure consistency in the width of every <li> element across the browser

Is there a way to make the ul element span the entire width of the webpage regardless of window size? http://jsfiddle.net/32hp1w5p/ ul { grid-column: 1/13; list-style-type: none; display: table; margin: 0 auto; } li { float: left; border: ...

Issues with jQuery selector (post-append)

While there are a few similar posts regarding this issue, my situation is slightly different and the suggested solutions have not worked for me (no typos in this case). When using jQuery, I am appending data to a div upon loading, creating a new div inside ...

How can I add text to a textbox within a duplicated div using Javascript or Jquery?

I'm looking to add text to a cloned div's text box using jQuery. I have a div with a button and text box, and by cloning it, I want to dynamically insert text into the new div. $(document).ready(function () { $("#click").click(function () { ...

Changing the border color of a Bootstrap 5 button using custom CSS styling

I have been working on a page to control my amp using various JavaScript libraries. 1.) How can I change the blue border of a selected Bootstrap 5 button to a lighter green without using SCSS? Example: Repository (apologies for the mess, it's not t ...

Django: Sending Templates through AJAX for Dynamic Rendering

Hey there, this is more of a theoretical question. So I recently discovered a cool trick: using AJAX to trigger a function that delivers a pre-rendered HTML template as a response, which can then be applied to a designated div element. This method feels i ...

Why does the CSHTML button containing a JavaScript onclick function only function intermittently?

I've implemented a download button on a webpage that dynamically assigns an ID based on the number of questions posted. Below is the code for the button: <input data-bind="attr: { id: $index() }" type="button" value="Downlo ...

Tips for creating a scrolling iFrame that moves with the background

I have recently created a website with a unique design feature. The background image acts as a border surrounding the main content, which is located within an iFrame. However, I've encountered an issue where scrolling the iFrame does not affect the ba ...

Using jQuery to Retrieve Check Box Labels and Populate Them into Textboxes

I would like to display the name of the selected checkbox label in a textbox. If multiple checkboxes are selected, I want their labels to be separated by commas and displayed in the textbox. Please excuse my poor English. $(document).ready(function() { ...

jQuery Validator on a "Page-Level" Basis

I've already created a custom jQuery validator method that is linked to one or more specific dropdown lists in my asp.net project. jQuery.validator.addMethod("dropdownBoxHasItemSelected", function (value, select, arg) { var returnValue = false; ...

How do I resolve the issue of Python doubling (" ") to ("" "")?

Here is an example of the code I am using without the website included. from bs4 import BeautifulSoup import requests import csv import random as rd source = requests.get('http://example.com').text file = open('C:/xampp/htdocs/new-site/text ...

Using Django Template Variables in JavaScript Functions

Within one of my templates, there is a for loop that iterates over all the items. Whenever a user likes or dislikes an item, it should trigger a function in my code. I successfully set up the button's HTML like this: <button onclick='update_li ...