Conceal a tag only visible at specific screen sizes

Is there a way to hide the following code when the screen resolution is 1024 X 768 or lower?

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ankitnagpal"></script>
<!-- AddThis Button END -->

If you have a solution, please provide some code snippets or references. It's important for compatibility with users on Win XP, especially those using IE.

Which technology would be best suited for this task? JavaScript, CSS, or jQuery?

Answer №1

When working with Internet Explorer versions prior to 9, media queries will not function as expected. In this case, it is advisable to utilize jQuery for targeted element manipulation.

if ( $(window).width() <= 1024 && $(window).height() <= 768 )
  $('.addthis_toolbox').hide();

While the above code snippet may not seem groundbreaking, incorporating

$(window).on('resize', function(){ ... });
allows for further customization if needed. To apply modifications at specific resolutions for multiple elements, consider CSS media queries and perhaps include a compatibility tool like respond.js for IE support.

Answer №2

give this a shot

  To check the window width, use:
  $(window).width() for width AND
  $(window).height() for height 

 var customWidth = 1200;
 if($(window).width() > customWidth)
  {
        //Don't display content
  }else{
       //Display content
  }

Answer №3

To determine the appropriate margin, you must utilize the following:

screen.height;
screen.width;

Once you have these values, you can calculate your margin accordingly. Keep in mind that

$(window).width() & $(window).height()
will provide the browser window's width and height, not the resolution.

For an example, visit here.

Answer №4

Utilize media queries for responsive design!

Ensure your code is wrapped in a designated container:

<div id="container">
    <!-- AddThis Button BEGIN -->
    <div class="addthis_toolbox addthis_default_style">
    <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
    </div>
    <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ankitnagpal"></script>
    <!-- AddThis Button END -->
</div>

Css:

@media screen and (max-height: 768px) and (max-width: 1024px) {
   .container { display: none }
}

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

Unable to execute Protractor using Node.js command line

Hi there! Currently, I am in the process of setting up protractor for the very first time using Node.js. I found detailed instructions on how to do this on the AngularJS website under the section "Running E2E Tests": https://docs.angularjs.org/tutorial Ho ...

Issue with parsing JSON occurs when utilizing jQuery in IE7 due to a "parseerror" being thrown

Encountering an issue in IE7 where it throws an exception: "jquery: parseerror" while executing the code below. The code functions correctly in other browsers like Firefox, Opera, Chrome, and Chromium. Code snippet: function check(){ $("#for ...

Refreshing the database with new information from an HTML table

Presented below is a table structure: <table id="skuTable" role="grid"> <thead> <th class="skuRow">Order</th> <th class="skuRow">Machine</th> <th>Fab. Date</th> <th cl ...

center text vertically in HTML list

Here at this festival, you'll find a unique menu on the sidebar. The menu is created using an HTML list with the following structure: <ul class="nav nav-pills nav-stacked"> <li class="active"> <a href="index.html"><i ...

The key to creating efficient routers in Express: Don't Repeat Yourself!

Currently, I am in the process of developing a web application in the form of a network structure that involves basic CRUD operations. However, I am facing the issue of having overly large router files, prompting me to consider splitting them up. One of t ...

Displaying grid in object in threejs: a tutorial

I currently have a horizontal grid Helper and polygon within my scene. Is there a way to hide the grid outside of the polygon, similar to the image below? https://i.sstatic.net/pQ40h.png Here is the JSFiddle var camera, scene, renderer, controls, geo ...

How can this be written in a shorter amount of CSS code?

Seeking a more optimized solution, I am attempting to write CSS transitions for five different elements (medals/badges). Is there a way to achieve the same effect with less code? Below is the current code: #nav .badges { float:left; height: 173px; width: ...

Adding a programmatic option with additional data

I am encountering an issue with my select2 multi-select element that has an ajax data source. Upon loading, I need to automatically preselect options in my select2. Although I have successfully followed the instructions outlined in the documentation for po ...

When calling canvas.getContext('2D'), the function returns a null value

After creating a canvas and calling its getContext() method, I was confused when it returned null for the context. Below is the code snippet that I used: <script> window.onload = initializeCanvas; function initializeCanvas(){ ...

Is there a way to validate form elements in HTML prior to submitting the form?

In my form, I am utilizing PHP for validation and processing, but I am interested in verifying elements as they are being filled out. Is there a way to check the current value of an element before the form is submitted? ...

Using default JavaScriptSerializer to bind DateTime to knockout view model

Recently, I started using knockout and encountered a problem with DateTime Serialization and Deserialization when using the JavaScriptSerializer. I modified the gifts model in Steve's koListEditor example from his blog to include a new field for Modi ...

retrieve information in the form of an array by making an AJAX request with the

Looking for a solution on how to send an array of strings as data from a PHP file? Check out the code snippet below: function getMods(){ var modsData; $.ajax({ type: "POST", url: "init.php", data: { 'id': getID()} ...

Enhance Your Internet Explorer Experience with AngularJS Blob URL Integration

Reviewing the following code snippet (taken from another source): var module = angular.module('myApp', []); module.controller('MyCtrl', function ($scope){ $scope.json = JSON.stringify({a:1, b:2}); }); module.directive('myDow ...

The display message in Javascript after replacing a specific string with a variable

I'm currently working on a task that involves extracting numbers from a text input, specifically the first section after splitting it. To test this functionality, I want to display the result using an alert. The text input provided is expected to be ...

Dealing with database errors while making AJAX requests in CodeIgniter

Intentionally making an error by using a wrong column name to learn how to handle errors with ajax calls in CodeIgniter. Last comment in the controller function is posing my question or problem My AJAX Code: I am utilizing the ajaxform plugin. It displa ...

Displaying information post-inquiry - Google Visualizations

I have a data-table using Google chart and I am looking to establish a connection with the table by sending a URL query. Once the query is sent, I want to display the retrieved data on my web page using JavaScript. How can I achieve this? Below is the cod ...

Ensure that you decode the URL before making any changes to the location in a

Hi everyone, I'm facing an issue and need your help. Let's say we have a URL like site.com/post?comments=1,2,3,4. When I paste it into the browser address bar, my app opens and decodes the URL to site.com/post?comments=1%2C2%2C3%2C4. How can I re ...

Is there a way to align both a list icon and its contents in the center?

Can someone please assist me? I am attempting to replicate a website, but I am unsure how to center align an icon list and content. Currently, it appears like this; https://i.stack.imgur.com/6FZCr.png I would like it to look like this; https://i.stack.im ...

The submit() function is completely unresponsive

I am facing an issue where the submit() function is not triggering as expected. The click event and AJAX call seem to be working fine, but the form is not getting submitted. I even tried using $("#storeForm").unbind().submit();, but it did not have any eff ...

Looking for a way to create a regular expression that can parse an email response containing the newline character?

Do you need help parsing only the most recent reply from the email thread below? For example, Hello Nikhil Bopora,↵↵Just to give a brief, I am in process of building an alternate e-lending↵platform. I tried using the general regex /[\s]*([&bsol ...