Obtain the text content of the currently visible column within a CSS multicolumn layout using

Utilizing CSS Multicolumn to display an HTML file, where the column width is set to match the window width, resulting in only one column being visible at a time

_windowWidth = $( window ).innerWidth();
. The column height is also adjusted to the window height
_windowHeight = $( window ).innerHeight();
, while the container's overflow property is hidden in the CSS overflow: hidden.

To switch between visible columns, I use the following code snippet

$('#content').css({"-webkit-transform":"translate(" + (-1 * _column * (_windowWidth + _columnGap)) + "px,0px)"});

I am looking to retrieve the text from the currently visible column.

$('#content').children(":visible").text();
returns all the text within the column.

The closest solution I have come across is on Stack Overflow: Get text in CSS3 column?. It suggests using this function:

var getAllTextInColumn = function(rect){
    /*
        rect should be the size and x,y of the column
        { top, left, width, height }
    */

    if(document.caretRangeFromPoint){
        var caretRangeStart = document.caretRangeFromPoint(rect.left, rect.top);
        var caretRangeEnd = document.caretRangeFromPoint(rect.left+rect.width-1, rect.top+rect.height-1);
    } else {
        return null;
    }

    if(caretRangeStart == null || caretRangeEnd == null) return null;

    var range = document.createRange();
    range.setStart(caretRangeStart.startContainer, caretRangeStart.startOffset);
    range.setEnd(caretRangeEnd.endContainer, caretRangeEnd.endOffset);

    return range.toString();
};

However, I'm unsure how to obtain the rect of a specific column (e.g., column 3).

Any assistance on this matter would be greatly appreciated.

Thank you in advance.

UPDATE:

This function does work but I am having trouble determining its parameters. When I input

left = 0 , top = 0 , width = _windowWidth , height = _windowHeight
, it retrieves the text of the first column.

When I input

left = _column * (_windowWidth + _columnGap) , top = 0 , width = _windowWidth , height = _windowHeight
with _column being either 0 or 1, it still fetches the text of the first column. If _column is greater than 2, caretRangeStart becomes null.

Trying variations like

left = 0 , top = 0 , width = _column * (_windowWidth + _columnGap) + _windowWidth , height = _windowHeight
results in caretRangeEnd becoming null, making it difficult to get the function working properly. Any help on finding the right combination would be highly appreciated.

Answer №1

Based on what you've explained, it appears that you are not specifically toggling the visibility of your columns. Instead, you seem to be adjusting the horizontal position.

A better approach would be to reverse this process: Calculate the x offset by dividing it by - (_windowWidth + _columnGap).

To extract the text, you can use the following code:

$('#content').children().eq(index).text();

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

How should form elements be named and handled for avoiding duplication?

Suppose my form contains 2 inputs <input name="person_name" value="John" type="text" /> <input name="person_name" value="Jean" type="text" /> After submitting the form, which "person_name" will be received? John or Jean? Also, what if I have ...

Creating an interactive graph in Asp.Net MVC using Razor syntax and jQuery AJAX

Currently, I am working on binding data to a graph using Razor. I am fetching the data through a jQuery ajax call and then planning to bind the resulting data to the graph. Is there a way to incorporate Razor code within the jQuery success function? Also, ...

Troubleshooting Tips: Removing a Specific Line from a Canvas Using Javascript

I need to find a method for removing a specific line without having to clear and redraw it. Learn more about clearing specific lines in Canvas with HTML5 I came across this question where everyone suggested clearing the entire page and redrawing it. Is t ...

The alignment of my Navbar Brand is off in my Navigation Bar and won't align to

<body> <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <div class="container-fluid"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs ...

Mastering the art of CSS float and positioning techniques

Struggling with CSS positioning yet again. I'm trying to design a webpage with one main element in the center, surrounded by 10 others. The challenge is to maintain consistency across different screen sizes (excluding mobile). However, every time I r ...

Deleting multiple subdocuments and their related subdocuments with Mongoose

In my application, I have a Project document that contains an array of subdocuments structured as Tasks. Each Task has its own array of subdocuments with a schema called Comments. const projectSchema = new Schema({ _id: Schema.Types.ObjectId, name: { ...

The validation function in jQuery form does not seem to function properly when implemented within tabs on a webpage

Currently, I have successfully implemented a POST form with validation using the Validate library from jquery. However, an issue arises when integrating the tabs function from bootstrap and other libraries to organize the form into multiple tabs. The pro ...

Having an issue with redirecting in Jquery Ajax after a successful call

I am trying to redirect the user to google.com after a successful AJAX request. However, the success function does not seem to be working or getting called at all. Below is the code snippet for the AJAX request: $('.modal2c').click(function() { ...

How do you add dynamic content to modals in AngularJS and Angular Strap based on the button that was clicked?

Is there a way to make the buttons in the AngularJS + AngularStrap modal more dynamic? Currently, they display static content, but I would like them to show the content of the first column (first name) of the exact row where the button was clicked. What is ...

Conceal the Navbar in React js when the user is in the dashboard

I am currently working on my collage project and I need to find a way to hide the navigation bar if the user is in either the admin, employee, or publisher dashboard. This means that the navbar should be hidden when the user is on the paths: /admin, /emplo ...

Modify the href link before submitting the request

Here is the code snippet that I am working with : <a class="myLink" href='http://www.website.it/'>Link</a> <script type="text/javascript"> var stringToSend = ""; $('.myLink').click(function() { string ...

What is the best way to preserve the state of child components after being filtered by the parent component?

I've been working on a small application using create react app to enhance my skills in React, but I've hit a roadblock with managing the state. The application maps through JSON data in the parent component and displays 6 "image cards" as child ...

Troubleshooting Issues with Form Inputs in JS/Angular Using Places API and document.getElementById Method

I have integrated the Google Places API to automatically populate locations/destinations into a form after a user searches. The auto-population works correctly, but I am facing an issue when trying to submit the form into my database – the object is alwa ...

Retrieving the data from the <input> tag using TypeScript

I'm currently working on retrieving user input values from a form. While vanilla JavaScript allows me to easily target elements and get their values using the .value method, I've encountered some challenges with TypeScript. Despite TypeScript bei ...

I am encountering an issue with my authentication system where it is returning

I'm currently experiencing an issue with my authentication system using passport. For some reason, I keep getting an 'undefined' value returned. Can anyone provide assistance? Here is the code snippet in question: app.js passport.use(new L ...

What is the best way to incorporate a dynamic key for AJAX data in jQuery?

I'm attempting to add a dynamic feature to my inline edit functionality by relying on data attributes from my HTML markup. Check out my current code below: $(".inline-edit").editable( function(value, settings) { var editableField = $(this); ...

Transform vertical and horizontal scrolling actions into solely horizontal scrolling using HTML and JS

I'm currently working on a unique React.js website that features a horizontal-scrolling portfolio. The website functions as a visual gallery, allowing users to easily scroll through images using their trackpad. Within the website, I have set up a lar ...

Exploring the world of pagination using AJAX (jQuery) - managing large datasets

Would it be wise to implement ajax pagination for large databases? I have a fast jQuery live search filter, but I'm concerned that I won't be able to use it alongside PHP pagination because the page content is typically generated from the databa ...

Choosing a radio button based on the stored value within a variable

When transferring a variable (active) from my route to EJS, I initially found it easy to simply display its value: <!-- Active Text Input--> <div class="form-outline mb-4"> <label for="active" class="form-label">Active</label> ...

What methods can be used to identify the css properties that are overriding ReactJS component styles?

:) I've been working on creating a website for some time now, and I decided to incorporate a react-calendar component from this link. Initially, when the page was simpler, it worked perfectly as intended and displayed like this based on the example p ...