[javascript] Show/hide 'div' using JavaScript

I found this question and recently I was implementing some UIs using Vue.js so this can be a good alternative.

First your code is not hiding target when you click on View Profile. You are overriding the content target with div2.

_x000D_
_x000D_
let multiple = new Vue({_x000D_
  el: "#multiple",_x000D_
  data: {_x000D_
    items: [{_x000D_
        id: 0,_x000D_
        name: 'View Profile',_x000D_
        desc: 'Show profile',_x000D_
        show: false,_x000D_
      },_x000D_
      {_x000D_
        id: 1,_x000D_
        name: 'View Results',_x000D_
        desc: 'Show results',_x000D_
        show: false,_x000D_
      },_x000D_
    ],_x000D_
    selected: '',_x000D_
    shown: false,_x000D_
  },_x000D_
  methods: {_x000D_
    showItem: function(item) {_x000D_
      if (this.selected && this.selected.id === item.id) {_x000D_
        item.show = item.show && this.shown ? false : !item.show;_x000D_
      } else {_x000D_
        item.show = (this.selected.show || !item.show) && this.shown ? true : !this.shown;_x000D_
      }_x000D_
      this.shown = item.show;_x000D_
      this.selected = item;_x000D_
    },_x000D_
  },_x000D_
});
_x000D_
<div id="multiple">_x000D_
  <button type="button" v-for="item in items" v-on:click="showItem(item)">{{item.name}}</button>_x000D_
_x000D_
  <div class="" v-if="shown">: {{selected.desc}}</div>_x000D_
</div>_x000D_
_x000D_
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.7/vue.js"></script>
_x000D_
_x000D_
_x000D_

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to onclick

How to use onClick with divs in React.js React prevent event bubbling in nested components on click React onClick function fires on render Run php function on button click Passing string parameter in JavaScript function Simple if else onclick then do? How to call a php script/function on a html button click Change Button color onClick RecyclerView onClick javascript get x and y coordinates on mouse click

Examples related to innerhtml

React.js: Set innerHTML vs dangerouslySetInnerHTML Angular 2 - innerHTML styling How do I clear inner HTML Show/hide 'div' using JavaScript How to get the innerHTML of selectable jquery element? Cannot set property 'innerHTML' of null Add/remove HTML inside div using JavaScript Javascript - Replace html using innerHTML Add inline style using Javascript It says that TypeError: document.getElementById(...) is null