jquery not responsive to font-size changes in textarea during screen resize

JavaScript Code

$(window).on('resize', function(){

    if ($(window).width() <= 800) { 
        $('textarea').css("font-size", "20x");
    } else {
        $('textarea').css("font-size", "30x");
    }

});

View Demo

I am attempting to decrease the font size within a textarea when the window width is less than 800px. Can you spot any errors in this code?

Answer №1

Why use jquery when you can achieve the same result using pure CSS? I have included a solution here as you have mentioned CSS in your question

This code snippet utilizes a @media query to dynamically adjust the font size of a textarea based on the window width

@media all and (max-width: 800px) {
    textarea {
        font-size: 20px;
    }
}

Check out the demo (Resize the window to see the effect)

Answer №2

It seems like you entered 20x, did you mean to use 20px? This sets the font-size in pixels.

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

Creating a Query String in a web URL address using the state go method in Angular State Router

On my product list page, there is a list of products. When I click on a particular product, a function is called that uses state.go. Issue with dynamic functionality: $state.go('home.product.detail', { 'productID': "redminote4", &apo ...

Transforming content dynamically

I am currently working on a single-page website that features a comprehensive product catalog. Here are the key elements I'm focusing on: A one-page website layout, complete with header, content, and footer (developed using HTML5/CSS3) Dynamic cont ...

Issue when attempting to animate an SVG point using translateX transformation

I am attempting to create a basic animation using the translate X property on a section of my svg when hovering over the element. Here is the code I have so far: <html> <style> .big-dot:hover { transform: translateX(20px); animat ...

"Encountering issues with toggle effect in nested divs when utilizing an Angular Directive -

I have included a link to the Plunker. Unfortunately, I am facing issues with accessing the elements .gc and .mc. On the other hand, the class .bc is functioning properly. My goal is to implement a toggle effect on them based on hierarchy: BroadCategory ...

Exploring the Wonderful World of Styled Components

I have a query regarding styled components and how they interact when one is referenced within another. While I've looked at the official documentation with the Link example, I'm still unclear on the exact behavior when one styled component refe ...

Guide to building a personalized autocomplete feature in vue js

Presently, I am using the buefy autocomplete feature, but it is causing a few problems. In the DepartmentDetail.vue file <template slot-scope="props"> <div class="container is-fluid"> <b-loading :is-full-page=" ...

Deleting images from Firestore using a Vue.js componentReady to learn how to remove images

I recently came across a Vue.js image uploader component that I am trying to repurpose (https://codesandbox.io/s/219m6n7z3j). This component allows users to upload images to Firebase storage and save the downloadURL to firestore for continuous rendering of ...

What is the best way to make sure my scrollbar only appears within a specific div?

I'm currently developing an angular single page application (SPA) that needs to generate multiple searchable lists of data within separate tabs. I have structured them like this: <body> <tabset> <tab> < ...

Extracting information from dynamically generated tables using Python 2.7, Beautiful Soup, and Selenium

I am in need of assistance with scraping a JavaScript generated table and saving specific data to a csv file. The tools available to me are limited to python 2.7, Beautiful Soup, and/or Selenium. Although I have referred to the code provided in question 14 ...

What is the best way to limit the input field to only allow up to 100 characters

I have implemented the min and max attributes in my code <input min="1" max="100" type="number"> Upon hovering over the input field, an error message is displayed stating "please select a value that is no more than 100." I am looking for a way to ...

The jQuery function fail() is triggered when the Flickr API fails to return data

I have been troubleshooting an issue with the Flickr Api url. It appears to return data correctly for my images when accessed directly, but I am encountering difficulties when trying to include it in $.ajax() and $.getJson(). The data does not load and the ...

Adjust the size of the embedded iframe to match the dimensions of the containing div

Is there a method to resize the iframe embed code for a vine so that it fits within the boundaries of the enclosing div? The supplied embed code already includes sizing information as shown below: <iframe src="https://vine.co/v/iMJzrThFhDL/embed/simp ...

What is the definition of the hashtag document?

I'm facing an issue while using the Selenium-Webdriver API in conjunction with ChromeDriver to perform a send_keys operation on an input field located within the <body>. The problem is that I cannot access any elements within the #document. I am ...

Tips for effectively interpreting a json string

Trying to extract specific fields from a JSON string and display them on an HTML page, but encountering the following error: SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data This is the JSON being sent: { "Order0& ...

Assigning the Access-Control-Allow-Origin header on the origin server

Currently, I am utilizing the $.get method in jQuery to parse an RSS feed. Below is a snippet of the code I have been using: $.get(rssurl, function(data) { var $xml = $(data); $xml.find("item").each(function() { var $this = $(this), ...

Are there methods to individually style components that have been generated through the .map() function?

My goal is to style each <Tuner /> component separately, which are being rendered for each item in the this.state.notes array using this.state.notes.map(). I want to position them individually on the page, but currently they all appear together. This ...

posting data and redirecting fails when using an ajax button

I am encountering an issue where I click a button on a page to navigate to another page with posted data, but it is redirecting without posting anything. Both $_POST and $_SESSION variables are empty. Below is my ajax function: function ajax4(Div_Submit, ...

Retrieve list of friend names along with their corresponding friend IDs from MongoDB

Creating a MEAN app for the first time and successfully inserting users into MongoDB. Each user entry includes: { "name":"My Name", "country":"Italy", "friends":"5922c66b4e708e27a02b7937" } First query: How can I manually add multiple friends (separate t ...

How can the onclick attribute be modified in an HTML document?

I am looking to update the data-pro-bar-percent attribute of a progress bar from 80 to 100 when a specific link is clicked. The change in attribute needs to be as follows: data-pro-bar-percent="80" --> data-pro-bar-percent="100" This is the current HT ...

Utilizing JADE in conjunction with ng-class

I'm having trouble getting this expression to work properly in my JADE nav-bar. It looks correct to me. li(ng-class="{'active' : true}"): a(href='#') INFO SHEET What am I missing here? The class doesn't get applied as expect ...