Can you stop an image from being chosen on a website?

I have a website that features a table with text descriptions in the headers and question mark images (users can hover over them for help).

Recently, I received a request to allow users to highlight and copy the table without including the images (using click and drag).

I attempted a solution from this source, but it did not work.

Is there a way to designate an image as 'no-copy' or 'no-select'?

Answer №1

Utilize a div element and apply the background-image property to set the background image as a question mark for the div element.

This particular div does not contain any text, making it unselectable.

To clarify further:

<thead>
  <tr>
    <th>header1</th>
    <th>header2 <div class="question-mark"></div></th>
  </tr>
</thead>


.question-mark{
    height: 100%;
    width: 10px;
    background-image: url("question_mark.png");
    background-repeat: no-repeat;
    background-size: contain;
    display: inline-block;
}

Answer №2

To follow the advice of fellow users, one option is to utilize a div element as an image container.

Alternatively, if you prefer to maintain your image as an actual image, you can implement the following code:

var img = document.querySelector("#notToDragImg");
img.onselectstart = function(){
                    return false;
                };

This will effectively prevent the selection of your image without the need for jQuery.

Answer №3

How to stop an image from being highlighted with CSS

img {
  user-select: none !important;
  -webkit-user-drag: 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

Discovering the clicking actions on PDF elements within an HTML environment

I am currently working on developing a web application that involves rendering various pdf objects. My main goal is to be able to detect the position of a click inside the pdf container. However, it seems like the OnClick event is not functioning as expe ...

Sorting and filtering data using AngularJS filter and orderBy inside a controller or factory

I am currently working with a factory that looks like this: app.factory("ModuleFactory", function (api, $http, $q, filterFilter) { var moduleList = []; var categoryList = []; var moduleTypeList = []; var academyModuleTypeList = []; var mostUsed = []; var ...

Is there a way to determine whether my CSS style modifications will impact other web pages?

Managing a team of junior developers has its challenges, especially when they unknowingly make CSS style changes that impact multiple pages on our website. Is there a tool or method available to alert them that modifying the color of a specific class will ...

JavaScript unable to remove cookie from system

I'm currently on an external website and attempting to use JavaScript to remove a cookie. Here's what I tried in the console: function deleteAllCookies() { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length ...

Prevent regex special characters in JavaScript while preserving the original string for keyword matching

As I develop my web page, I encountered an issue while trying to highlight text based on user input in the search box. My search algorithm matches each space-separated keyword, but ran into problems when including brackets in the search term. This caused a ...

What are some ways I can utilize Babel in standalone mode to convert an HTML import into a variable declaration?

I am trying to utilize the Babel plugin babel-plugin-transform-html-import-to-string to dynamically transform my code in the browser client. However, the babel-plugin-transform-html-import-to-string is designed to run on node with file libraries, which are ...

Instructions for adding an onfocus event listener to an input field in order to dynamically change the formatting of associated labels

I'm looking to change the style of my input labels to a more fancy look by implementing the .fancyclass style when using the onfocus event on the input field. I am curious to know how this can be achieved through event listeners in Javascript? ...

UVs on a single object in my Three.js project are completely messed up

I've been working on a 3D house model and encountered another frustrating issue that seems to be common with three.js. In Maya, I have created my scene with 9 ungrouped objects, each only a child of the world, with texture maps containing ambient occ ...

How to target a class with a specific number in CSS selectors

My mobile hybrid application is built with Sencha Touch 2 and requires some customization based on the iOS version it's running on. In my Sass stylesheet, I originally had the following selector: .x-ios-7 { /* add iOS7 customizations here */ } How ...

A guide on activating the Bootstrap v5 Offcanvas with toggle buttons

How can I trigger the Bootstrap V5 Offcanvas using Bootstrap switches? I want the Offcanvas to open when the switch is checked and close when the Offcanvas is closed. Sample Code : <!-- Using checkbox switches to open the offcanvas --> <div class ...

Finding the right spot to apply CSS styles in a data table can be a tricky task

I need to use angular-ngStyle to apply CSS styles on Table data. The logic is set up: "When the table width is less than 1250px, apply certain CSS styles". Here is the code for that: export class NanoTableComponent { /** * This function checks the table ...

Repeating calls to the init() function within an AngularJS controller

Encountering an issue while developing an angularjs application. I have set up a controller and bound it in routeProvider with a function to initialize values like so: angular.module('app.Login', ['app.rpc','ngRoute']) ...

Transferring data from an HTML input to a Python script and displaying the output on a webpage through the Django framework

I'm currently working on passing a string from an input field in my HTML frontend to a Python file/function that interacts with the Google API. My goal is to display the retrieved information back on the webpage. Unfortunately, I'm having trouble ...

Using regular expressions to extract information from HTML code with the JSoup library

I am working on extracting values from a web page source file using HTML rules that I currently have: e=d.select("li[id=result_48]"); e=d.select("div[id=result_48]"); Here are the relevant HTML tags: <li id="result_48" data-asin="0781774047" class="s ...

Listening for Angular 2 router events

How can I detect state changes in Angular 2 router? In Angular 1.x, I used the following event: $rootScope.$on('$stateChangeStart', function(event,toState,toParams,fromState,fromParams, options){ ... }) In Angular 2, using the window.addEv ...

PHP file upload error: Angular JS form submission issue

I am currently working on creating an upload method using Angular and PHP. Here is what I have come up with so far... HTML <form class="well" enctype="multipart/form-data"> <div class="form-group"> <label for ...

A guide on updating data with duplicate values in Knex

Suppose I have the following array of data: const customerIds = [ '7d8206d2-74bc-4b90-a237-37f92486cde4', 'e594fe7f-d529-4a2f-ab24-ffc4e102268c', '7d8206d2-74bc-4b90-a237-37f92486cde4' ] As seen, there are duplicate IDs ...

Animated CSS sidemenu (utilized as a filtering panel for a table)

Hi there, I'm having some trouble with CSS Animation. I recently started developing websites and am using Bootstrap 4 along with Animate.css for animations. My goal is to have an icon button expand sideways to reveal a div containing select elements f ...

Tips for enhancing the efficiency of a three.js environment within Gatsby.js or react:

I am dealing with a straightforward three.js scene that is rendered using an useEffect hook. The scene loads a model using GLTFLoader(). On the page, there are three event listeners triggered on load. One calculates the browser's inner height, anothe ...

Execute HTML code within a text field

Is it possible to run html code with javascript inside a text box, similar to w3schools.com? I am working solely with html and javascript. Thank you. For example, I have two text areas - one for inserting html, clicking a button to run the code, and displ ...