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

Contains a D3 (version 3.4) edge bundle chart along with a convenient update button for loading fresh datasets

I am looking to update my D3 (v3.4) edge bundling chart with a new dataset when a user clicks an 'update' button. Specifically, I want the chart to display data from the data2.json file instead of data1.json. Although I have started creating an u ...

Having trouble with Firebug throwing a '$(' error message?

I'm encountering a peculiar issue in Firebug that I'm not experiencing in Webkit. The error being displayed is '$(' in Firebug. Here is the code that seems to be causing this problem: $.getScript("http://kylehotchkiss.com/min/?g=packa ...

Formulate a multi-line string using a collection in React's JavaScript framework

I'm working on a React function that involves a set and I need to update an HTML element using the data from this set. Below is an example of my code: const updateElement = (mySet) => { document.getElementById('myId').innerHTML = Arra ...

CSS text wrapping will now occur on underscores as well as spaces and hyphens

I am facing an issue with long file names in my HTML formatting causing overflow. These file names use underscores instead of spaces, making it difficult to wrap them properly. For example: Here_is_an_example_of_a_really_long_filename_that_uses_underscore ...

The Bootstrap slide function encounters issues within the AJAX success callback

Here's the code snippet with a 'slide' event inside an AJAX success call. success: function(data) { $('#my_container').html(data); // Successfully loading #mycarousel into #my_container $('#mycarousel').bind( ...

Is there a way to prevent duplicate requests in jQuery?

I'm new to using jquery. Can someone please assist me with solving my current task? Here is the code that I have for a form with a select element. It triggers on the onfocus event: function sendBall(id){ $('#bal_'+id).blur(function(){ $.aj ...

Rendering json data in jquery

Is there a way to load a .json file from the assets folder into a jquery script within a grails application? Below is the jquery code snippet I have written to handle this: let dropdown = $('#banks'); dropdown.empty(); dropdown.append(' ...

The webpage content is failing to display once the HTML document has finished loading

My goal is to load an advertisement after the page has loaded using jQuery's html() method. However, I am facing an issue where the $(document).ready(function(){ function is causing a redirect, displaying only the advertisement without any other data. ...

The Impact of CSS Border Width on the Size of a PHP Form

Creating a PHP form with a tabbed box has been quite the challenge. With 3 tabs, each requiring different field inputs, I set out to add a border around the form headings and tabs. The border looks great, but it poses a problem - its width spans the entire ...

Tips for sending an array of "FormData" through ajax and retrieving it in a Laravel controller

# Could you please provide guidance on sending this array to the controller via Ajax request? var dataPanier=[]; function addarray(objser) { dataPanier.push(objser); } $('.target').click(function() { var btn_name=$(this).attr("name"); ...

Adding a stylesheet dynamically to the <head> tag using $routeProvider in AngularJS

Is there a way to load a specific CSS file only when a user visits the contact.html view on my AngularJS application or site? I came across this helpful answer that almost made sense to me How to include view/partial specific styling in AngularJS. The acce ...

What steps can I take to maintain the width while implementing jQuery's slideUp function?

I am facing a scenario where: http://www.jsfiddle.net/kPBbb/ After adding content to .content, the .wrapper shrinks itself, possibly due to the fact that the .content is set to display: none. I want the .wrapper to maintain its original size even after t ...

"Implementing jquery autocomplete feature with the ability to fetch data from

Currently, I am utilizing jquery's ajax functionality to retrieve data from an external php file. The retrieved data is then intended for use in the autocomplete feature. However, instead of displaying individual values from the array in the php file ...

Non-responsive Click Event on Dynamically Created Div Class

I am facing some uncertainty in approaching this problem. In the HTML, I have created buttons with additional data attributes. These buttons are assigned a class name of roleBtn. When clicked, they trigger the jQuery function called roleBtnClicked, which ...

Concealing option value based on ng-if conditions in AngularJS: A guide

I am designing an Input form with two input fields that need to be compared and values displayed if a certain condition is met. The input fields are: <td class="td_label"><label>Client Age :</label></td> <td class="td_input"> ...

Verify the accuracy of the color value on a web page using Selenium in Java

As a beginner in using Selenium with Java, I encountered an issue related to a symbol in my connected class turning green. I needed to assert whether the symbol actually changed its color. Below is the code snippet that I used: Boolean connectionSymbolG ...

Setting a fixed height for layout with scroll functionality in Twitter Bootstrap 3.2.0

I am currently working on a design layout using bootstrap 3.2.0. I have managed to create a Fixed header and footer, and I am now facing the challenge of having a full-height container with independent scrollbars. Are there any effective methods in Twitter ...

Preserving CSS styling while loading an HTML page with InnerHTML

By using the following code snippet, I have successfully implemented a feature on my website that allows me to load an HTML page into a specific div container when clicking a link in the menu. However, I encountered an issue where the background color of ...

Pair of Javascript Functions Using Async with Parameters

This question builds upon a previous inquiry raised on Stack Overflow: When considering approach number 3 (referred to as the "counter" method), how can we ensure that the function handleCompletion can access necessary data from startOtherAsync to perform ...

The Angular factory function was unable to be initialized

I recently started learning how to integrate Angularjs with ROR using this helpful tutorial While working on adding a new function to retrieve all posts from the database, I encountered a problem. The page no longer loads when I run the code and the HTML ...