Is there a way in JavaScript to disable a function's functionality?

I am dealing with a function that includes an if statement and an onclick function. My goal is to prevent the entire function from running if the if statement evaluates to true. I have attempted using return false, but it did not yield the desired outcome.

showLogo: function(row) {
  var a = 0;
  window.onclick = (e => {
    let element = e.target.className || e.srcElement.className
    let element1 = e.target || e.srcElement
    if (element1.localName == "li" || element == "pagination-previous" || element == "pagination-next" || element === "pagination-link" || element === "icon" || element === "fa fa-angle-right fa-lg" || element === "b-table" || element === "level" || element === "pagination" || element === "fa fa-angle-left fa-lg") {
      this.logo = false
    }
  });
  if (window.innerWidth > 1024) {
    this.logo = true;
    this.color = false;
    this.istabModalActive = false;
    this.name = row.fileName;
    this.dimension = row.width + ' x ' + row.height
    this.width = 0;
    this.height = 0;
    this.src = row.path;
    this.icon = row.iconsrc;
    this.dlsrc = row.path;
    this.contentType = row.contentType;
    this.typeshow = row.contentType.split("/")[1].toUpperCase();
    this.type = row.contentType.split("/")[1];
    this.icons = 'dist/' + this.type + '.svg';
    this.assetsid = row.index;
    this.size = row.size;
    this.activerow = row;
    this.fileid = row.id;
    this.assetsid = row.id;
    this.activerow = row;
  } else {
    this.logo = true;
    this.color = false;
    this.istabModalActive = true;
    this.filesarr = row;
    this.name = row.fileName;
    this.dimension = row.width + ' x ' + row.height
    this.size = row.size;
    this.src = row.path;
    this.icon = row.iconsrc;
    this.dlsrc = row.path;
    this.typeshow = row.contentType.split("/")[1].toUpperCase();
    this.type = row.contentType.split("/")[1];
    this.icons = row.iconsrc;
    this.fileid = row.id;
    this.assetsid = row.id;
    this.activerow = row;
  }

}

Answer №1

displayLogo:function(row){
    var a = 0;
    var flag = 0;
    window.onclick = (e => {
        let element = e.target.className || e.srcElement.className
        let element1 = e.target || e.srcElement
        if (element1.localName == "li" || element == "pagination-previous" || element == "pagination-next" || element === "pagination-link" ||  element === "icon" ||  element === "fa fa-angle-right fa-lg" ||  element === "b-table"||  element === "level"||  element === "pagination" ||  element === "fa fa-angle-left fa-lg") {
            this.displayLogo = false;
            flag = 1;
        }


        }); 
                if(window.innerWidth> 1024 && flag == 0)
                {
                this.displayLogo = true;
                this.color = false; 
                this.isModalActive = false;
                this.name = row.fileName;
                this.dimension = row.width +' x '+row.height
                this.width = 0;
                this.height = 0;
                this.source = row.path;
                this.icon = row.iconsrc;
                this.downloadSrc = row.path;
                this.contentType = row.contentType;
                this.typeDisplay = row.contentType.split("/")[1].toUpperCase() ;
                this.category = row.contentType.split("/")[1];
                this.icons = 'dist/'+this.category+'.svg';
                this.assetId=row.index;
                this.size = row.size;
                this.activeRow = row;
                this.fileId=row.id;
                this.assetId=row.id;
                this.activeRow = row;
                }
                else if(flag == 0) {
                this.displayLogo = true;
                this.color = false; 
                this.isModalActive = true;
                this.filesArray=row;
                this.name = row.fileName;
                this.dimension = row.width +' x '+row.height
                this.size = row.size;
                this.source = row.path;
                this.icon = row.iconsrc;
                this.downloadSrc = row.path;
                this.typeDisplay = row.contentType.split("/")[1].toUpperCase() ;
                this.category = row.contentType.split("/")[1];
                this.icons = row.iconsrc;
                this.fileId=row.id;
                this.assetId=row.id;
                this.activeRow = row;   
                }

},

Answer №2

handleWindowClickEvent : function() {
  window.onclick = (e => {
        let element = e.target.className || e.srcElement.className
        let element1 = e.target || e.srcElement
        if (element1.localName == "li" || element == "pagination-previous" || element == "pagination-next" || element === "pagination-link" || element === "icon" || element === "fa fa-angle-right fa-lg" || element === "b-table" || element === "level" || element === "pagination" || element === "fa fa-angle-left fa-lg") {
          this.logoVisible = false
        }
      });
}  
displayLogo: function(row) {
      var a = 0;

      if (window.innerWidth > 1024) {
        this.logoVisible = true;
        this.colorVisible = false;
        this.tabModalActive = false;
        this.name = row.fileName;
        this.dimension = row.width + ' x ' + row.height
        this.width = 0;
        this.height = 0;
        this.src = row.path;
        this.icon = row.iconsrc;
        this.downloadSrc = row.path;
        this.contentType = row.contentType;
        this.contentTypeToShow = row.contentType.split("/")[1].toUpperCase();
        this.type = row.contentType.split("/")[1];
        this.icons = 'dist/' + this.type + '.svg';
        this.assetId = row.index;
        this.size = row.size;
        this.activeRow = row;
        this.fileId = row.id;
        this.assetId = row.id;
        this.activeRow = row;
      } else {
        this.logoVisible = true;
        this.handleWindowClickEvent.call(this)
        //thismay solve your problem
        this.colorVisible = false;
        this.tabModalActive = true;
        this.filesArray = row;
        this.name = row.fileName;
        this.dimension = row.width + ' x ' + row.height
        this.size = row.size;
        this.src = row.path;
        this.icon = row.iconsrc;
        this.downloadSrc = row.path;
        this.contentTypeToShow = row.contentType.split("/")[1].toUpperCase();
        this.type = row.contentType.split("/")[1];
        this.icons = row.iconsrc;
        this.fileId = row.id;
        this.assetId = row.id;
        this.activeRow = row;
      }

    }

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

Tips for effectively logging data retrieved through Ajax requests

When I have content loaded via Ajax with two divs and a list, my goal is to console.log which div I was typing on when clicking on a list item. However, the issue I'm facing is that I always get the first one I clicked until I refresh the page. Altho ...

transition from mapStateToProps to using hooks

Just dipping my toes into the world of React (hooks) and learning by writing code. I'm grappling with converting MapStateToProps to hooks, specifically stuck on one part just before 'currentItem'. Here's the original code snippet: co ...

Is it possible to dynamically load records in real time with the help of PHP and jQuery?

I developed a custom system using PHP that allows users to post status messages, similar to a microblog. The system utilizes a database table structured like this: posts_mst ------------------ post_id_pk post_title post_content date_added Initially, I su ...

Error message: "Receiving a 'TypeError' in Node.js async parallel - the task is not recognized as a

Currently, I am utilizing the async module to run multiple tasks simultaneously. In essence, I have two distinct files named dashboard.js and Run.js. Dashboard.js module.exports = { func1 : function(){ console.log(“Function one”); }, ...

Setting up an abstract state as the backdrop in AngularJS: A step-by-step guide

I am trying to maintain an animated background while switching between different states in my UI-router setup. The goal is for the background to remain constant while only the content of the states changes. Here is how I have set up my UI-router and attem ...

Modifying the attributes/properties within a class of a bootstrap button

Here is the code that I have: <b-button id="search-button" size="md" class="mt-1 w-100" type="submit" @click="someEvent()" >Example </b-button If we imagine calling someEvent() and wanting to modi ...

Having difficulties executing a JavaScript file in the command prompt

I'm having trouble running a JavaScript file in the command prompt. Can anyone assist me with this issue? D:\>Node Welcome to Node.js v12.14.1. Type ".help" for more information. > 001.js undefined > Node 001.js Thrown: Node 001.js ...

Is there a way to retrieve a data property in a Vue file's template without relying on props?

In my Laravel + Vue.js SPA (Single Page Application), I have implemented BootstrapVue and VeeValidate libraries. Within the EditProfile.vue component, I need to access the default_country_code data property from an attribute in the template with the same ...

Set up webpack on your Mac using npm

Seeking help to install webpack using npm: sudo npm install -g webpack The following error message is encountered: node-pre-gyp WARN Using needle for node-pre-gyp https download node-pre-gyp WARN Pre-built binaries not installable for <a href="/cdn- ...

What are some ways to disguise websockets?

I'm currently working on writing a JavaScript client that sends websockets to a node.js/ws server. I've been doing a lot of research and have come across information indicating it's useful, or even required by RFC, to mask all data sent from ...

Fetch operates based on the specified categoryId

Hey there, I'm currently in the process of learning JS and trying to fetch data from an API. I've successfully fetched all the work from api/works and displayed them in a div. Now, I'm looking to create 3 buttons that represent 3 categories ...

Exploring JSON data hierarchies with AngularJS using ng-options

In my web app, I am utilizing AngularJS to create two dropdown lists using ng-options. The first dropdown displays a list of countries The second dropdown provides language preferences for the selected country As I am still new to AngularJS, I am able t ...

Stopping free jqgrid disabled toolbar buttons from reacting to mouse clicks can be achieved by implementing specific coding techniques that

When using Free jqgrid, toolbar disabled buttons may trigger click events on mouse clicks which can lead to invalid code execution. To demonstrate this, open the page below in Chrome and click on a disabled inline edit or pager button. A rectangle will app ...

The attempt to remove a cookie through a Next.js server-side operation was unsuccessful

Having trouble removing a cookie using the next/headers module in my Next.js application. The code snippet below is what I've tried: import {cookies} from "next/headers"; export default async function Signout() { async function deleteTok ...

Deliver integers using Express.js

When I try to send a response with Express using the code below, it doesn't work: res.send(13245) An error message is displayed: express deprecated res.send(status): Use res.sendStatus(status) instead src/x.js:38:9 (node:25549) UnhandledPromise ...

Scroll through the menu with ease

I am facing an issue with my menu that has 2 levels. Whenever I try to scroll down, I want the position of the Logo to change to the bottom of the menu smoothly. However, during scrolling, there is a noticeable shake in the menu movement which makes it app ...

Exploring the structure and dispersion of files within a VueJS project: An architectural inquiry

As I delve into learning VueJS, I've come to understand that .vue files typically consist of three distinct parts: <template>, <script>, and <style>. My query pertains to how these three parts are managed in a professional VueJs pro ...

Unveiling Parameters from a Function Transferred as an Argument to Another Function in JavaScript

I'm just getting started with JavaScript and I've encountered a small program where a function takes another function as an argument. My goal is to figure out how to extract or access the arguments of that passed in function. Here's a specif ...

Leveraging angular.forEach for JSON Iteration

In my app and controller, I am working on creating a "flow chart style" question and answer system. To keep track of the current question and answer, I am using variables like $scope.ActiveQuestion and an array named $scope.ActiveAnswers. I am struggling ...

Getting a string from JSON using Javascript

I am trying to retrieve a specific skill from a variable: const skillsData = [ { name: "React", value: 390 }, { name: "CSS", value: 1200 }, { name: "JavsScript", value: 540 }, { name: "HTML", value: 1900 }, ...