What is the best way to swap out an HTML element based on the size of the screen?

Is it feasible to switch out an <ol> element for a <ul> element based on media query? The desired outcome in desktop mode is:

    <ol>
     <li></li>
     <li></li>
     <li></li>
    </ol>

while in mobile mode it should be:

    <ul>
     <li></li>
     <li></li>
     <li></li>
    </ul>

Can this conversion be achieved using media queries or jQuery?

Answer №1

If you're wondering whether it's possible, you can assign a class to each list and manipulate them using displays:

<ol class="first-list">
<li></li>
<li></li>
<li></li>
<li></li>
</ol>

<ul class="second-list">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>

Then, in your CSS file:

@media(max-width:768px){
    .first-list{
        display:none;
    }
    .second-list{
        display:block;
    }
}

You can customize the max-width value as needed.

Answer №2

Instead of using multiple lists (ol and ul), you can change the list style based on a media query:

@media (max-width: 640px) {
  ol {
    list-style-type: disc;
  }
}

This means that initially it will be an ordered list (OL) with decimals, but when the screen size hits a certain point (e.g. mobile), it will change to a circle style (disc). This is a better alternative than having both types of lists if you only need one.

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

Update article translation dynamically in Vue without needing to refresh the page

ArticleController public function index() { $locale = Lang::locale(); // $locale = Lang::getLocale(); $articles = Article::withTranslations($locale)->get(); return $articles; } resources/assets/js/pages/articl ...

Sending a string to the server-side using Jquery Ajax

Is there a way to send variable data to the server side? I am looking for a solution. $("form").submit(function () { GetSelectedValues(); }); function GetSelectedValues() { var data = $("#DDL_WorkCategory").val(); } This ...

how to use jQuery to sort appended data

I have a loop that retrieves data from the server in descending order, but when I use "append()" to add the data, it doesn't maintain the correct sorting. For instance, the first row shows up in the second position. Is there a way to append the data ...

Extract information from a division and transfer it to a table when clicked

I have several div elements, each containing a button. When a user clicks the button, I want to transfer the content of that specific div into a new table row. Although I've managed to create a new table row when the button is clicked using a fiddle, ...

Concealing the table border with the help of jQuery

I am working with a dynamically created tables in a ASP.NET repeater, where the number of tables can vary depending on the data retrieved from the database. Below is a sample markup along with the CSS and jQuery code. Please note that the tables are dynami ...

What is the best method for displaying multiple slices within an SVG circle?

I'm currently working on a project involving a reactJS application. The goal is to display an svg circle that, when clicked, divides into n equal slices. I have successfully generated the individual slices with the following code: renderSlices = () ...

Tips for incorporating tabs using jQuery

Check out this code snippet: <script> $(function() { $("#tabs").tabs({ event: "mouseover" }); $("#tabs").tabs("add","#tab-4","Friends Discussions"); $("#tabs").tabs("add","#tab-5","Announcements"); $("#tab ...

How can I prevent jQuery Explode from changing fonts during the explosion effect?

When you visit , click on any scholarship name. Then, click on the "close" button, and you will notice that while "exploding," the font changes from the default "Trebuchet MS/Trebuchet" to "Times New Roman." Despite trying to define the body as {font-famil ...

The routeLink feature is unable to display the URL dynamically

https://i.sstatic.net/iD53V.png <table class="table"> <thead> <tr> <th>Name</th> <th>Price</th> <th></th> </tr> </thead> ...

Tips on extracting and displaying data from a JSON response in JavaScript to HTML

Hello! I'm new to JavaScript and I have a question regarding AJAX requests. I've successfully received a JSON response and I want to dynamically append specific data from this response to HTML fields. Below is an example of the JSON response tha ...

Dealing with local URL issues in Windows 10 UWP Webview

Windows 10 UWP Webview I have a Windows 10 UWP project with two HTML files located in a "www" folder under Assets: Assets/www/xxx.html. In Visual Studio 2015, both files are set to be copied to the output directory. index.html <!DOCTYPE html> < ...

jQuery is unable to manipulate newly added DOM elements that have been loaded via AJAX

Having trouble with jquery ajax. Unable to interact with newly added element through ajax. Code snippet: $(".yorum_input").keypress(function(e) { if (e.keyCode == 13) { e.preventDefault(); var alt_id = $(this).attr('yorum_id'); va ...

Guide to loading MVC views within navigation tabs

Embarking on my first website creation journey using C#/MVC 4 and incorporating Twitter Bootstrap CSS/UI views has proven to be quite the challenge. The site consists of 3 navigation tabs: Home, About, Contacts. I was unaware that loading various pages ( ...

Combining JSON data in Typescript using the merge method

Is there a way to effectively merge JSON objects in such a manner that simple values (strings, numbers, booleans, etc) get overridden when keys match, but when dealing with complex values (arrays and objects), different outcomes apply? 1.) For simple array ...

Displaying Bootstrap alert after a successful jQuery AJAX call

I have been attempting to display an alert on a form once the submission action is completed. Here is my JavaScript function: function submitForm(){ // Initialize Variables With Form Content var nomeCompleto = $("#nomeCompleto").val(); v ...

What is the best way to extract the value from a textangular editor within an ng-repeat loop

I am using the TextAngular editor within an ng-repeat loop. Within the HTML <ul ng-repeat="lecture in section.lectures"> <div class="col-md-12 article-show" > <form ng-submit="lecture_content('article', $index + 1, l ...

What is the reason behind the issue where max-height disrupts border-radius?

My inline svg is styled with the following CSS: .img { border-radius: 15px; overflow: hidden; max-width: 70vw; margin-top: 6vh; max-height: 50vh; z-index: -1; text-align: center; } Everything seems to work as expected, except f ...

Guide on detecting and capturing a change in location history event

My main goal is to capture router change events outside of the NextJS framework, not within it. The application I have developed using NextJS includes some code that operates independently of the NextJS context. This code needs to be able to detect navigat ...

Obtain the actual file path from a JSON response

I have set up a local express server to serve a JSON file, but I am facing an issue with displaying image files located in a local folder. The image paths are included in the JSON object that I want to display in my DOM. However, the response I receive inc ...

What is causing the script blocks to exponentially increase in size within the VS2010 Debugger while executing an ASP.Net page with partial postbacks?

When working on an ASP.Net page that utilizes an UpdatePanel with validated controls for partial postbacks, an issue arises with the Visual Studio 2010 script debugger window. The debugger window starts displaying a continuous list of "Script Block" entrie ...