How can text be effectively shortened for small screen sizes?

Let's consider a scenario: Imagine on my website footer, at 1024px resolution screen, I have a link that says "Terms & Conditions" among other links. Now, using media queries, if the screen width is reduced to max-width: 320px, I would prefer to shorten the link to just "Terms". There are two approaches to achieve this:

JAVASCRIPT METHOD

HTML

<p class='terms'>Terms &amp; Conditions</p>

JAVASCRIPT

// Determine breakpoint and then use this script:
$('.terms').text('Terms');

CSS METHOD

HTML

<p class='terms'>Terms <span>&amp; Conditions</span></p>

CSS

@media screen and (max-width: 320px) {
  .terms span {
     display: none;
  }
}

Is there a preferred approach for this task? Personally, I find the CSS method to be more efficient.

Answer №1

Opting for the CSS solution is recommended if jQuery isn't utilized elsewhere on this site. But if you're already implementing jQuery, both methods are equally efficient - users won't experience any discernible variance.

Answer №2

It's mainly a matter of personal preference, but I lean towards the CSS solution for its maintenance benefits. Most responsive design frameworks are heading in that direction, making it easier to locate and manage presentation definitions in CSS.

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

utilize JavaScript on every element that has a specific identifier

<a id="link" href="http://www.google.co.uk">link</a> <a id="link" href="http://stackoverflow.com">link</a> Is there a way to make the JavaScript code apply to all <a> tags with the id="link", instead of just the first one? A ...

Adding data to GridView

Is there a way to dynamically load more records from the database, similar to how Facebook works with their 'see more' button in the footer of a grid view? I want to accomplish this without having to do a full post back on the grid. Can this be d ...

Looking for assistance with utilizing Gridster plugin in Rails for AJAX requests

Embarking on my first jQuery AJAX post and delving into JSON for the first time, so please bear with me. I'm having trouble getting the ID of the record into the URL string, so I added a 'move' method to the crud controller and included this ...

How can I parse URL paths in jQuery for ASP.NET?

I want to incorporate "~/" and have it resolved on the client side. Here is an example of what I am trying to do: <a href="~/page.aspx">website link</a> <img src="~/page.aspx" /> In my ASP.NET code, I have my base URLs set up like this ...

Using Jquery to dynamically set value for select form input

I have almost completed a webshop with a product catalog page featuring multiple products, as well as a product information/overview page focusing on a single product. The product catalog page currently includes a "read more" button that redirects to the ...

What is the process for making an ajax call in CakePHP?

It may seem obvious, but I've searched the internet and couldn't find any useful or updated information on this topic. I'm attempting to make an ajax request in CakePHP controller to retrieve both view contents and JavaScript code. The aja ...

Expanding Form Fields with jQuery: A Step-by-Step Guide

I am having trouble figuring out how to add and remove input fields dynamically on my webpage. I have three input fields with an "+Add More" button, but I can't quite grasp the logic for adding or removing these fields. Currently, I am using HTML and ...

Retrieve the .js file from a WordPress plugin

I need assistance with loading a .js file from a WordPress plugin. Within the main plugin file, I have code that loads jQuery, jQuery-UI, and my .js file: //Load Java and Jquery function load_jquery() { // only use this method if we're not in wp ...

unable to respond when clicking an angularjs link

I'm facing an issue where I can't get a link to respond to click events in AngularJS. When I click on the anchor link, nothing happens. Here is a snippet of the AngularJS script: <script data-require="<a href="/cdn-cgi/l/email-protection" ...

Querying with Codeigniter in Ajax Data table only returns a single row

When using codeigniter to create an ajax data-table, I pass the User ID as a condition to retrieve records from a product orders table. $this->datatables->select('orders.order_user_id,orders.order_date,orders.order_id,orders.order_confirmation_ ...

Developing a WordPress click counter using AJAX

Struggling with coding an AJAX click counter for WordPress. I've spent days attempting to figure it out without success. The issue lies in a template page that showcases mixtapes/albums from a custom post type, all of which are downloadable. Since the ...

Issues with slideToggle in IE8 caused by CSS in JQuery

I am facing an issue where my div elements are supposed to toggle visibility using jQuery's "slideToggle" function (I'm utilizing jquery-1.2.6.min.js). This functionality is working as expected! However, I am encountering a problem specifically w ...

Retrieve data from AJAX once the cycle is complete

Currently, I am attempting to calculate the sum of results from an external API by making a single request for each keyword I possess. The code is functioning properly; however, the function returns the value before all the ajax requests are completed. Eve ...

Styling Text with Shadow Effects in Mobile Web Browsers

I'm attempting to apply a text-stroke effect using text-shadow like this: .text-stroke { text-shadow: -1px -1px 0 white, 1px -1px 0 white, -1px 1px 0 white, 1px 1px 0 white; } Unfortunately, it's not rendering correctly on mobile versions of Fi ...

The CSS property :last-of-type seems to be malfunctioning

As I work on creating an HTML form and incorporating CSS into it, here is a snippet of my HTML structure: <html> <body> <div class="pt-form row"> <!-- This will be the top layer for input box --> <div class="pt-form-input ...

Transmitting solely the updated information from the database

I am working on a table that is populated with data from the server using ajax. The table has columns A, B, C, and D where C and D are editable by the user. After the user makes changes to the data in the table, I need to capture only the lines that have b ...

Unable to implement a delegate method effectively

I am currently facing an issue with using Ajax in a bootstrap PHP page. The problem is that I cannot use functions inside the onsubmit event because the button does not exist beforehand. Therefore, I have to resort to using delegate methods instead. Howeve ...

Dreamweaver seems to struggle to properly execute the identical code

There are times when I transfer javascript code from jsfiddle to Dreamweaver and find myself frustrated. Two documents with seemingly identical javascript don't function the same way. In document A, I have this code: <script> alert('test& ...

Create an XPath by utilizing the class and text attributes of a div element

Struggling to create a relative xpath for use with webdriver, none of the ones I've attempted seem to be working. Here is my Web Element: <div class="pa-PrimaryNavWidget-hyperlink" style="color: rgb(255, 255, 255); cursor: default; background-col ...

CSS is being applied on Internet Explorer 11 only after a hard refresh with Ctrl+F5

While my website loads perfectly in Chrome and Firefox, I have been experiencing issues with Internet Explorer 11. The CSS is not fully applying until after pressing Ctrl+F5 multiple times. It's strange because some of the CSS is being applied but cer ...