Vue add class to element without v-model:class?












0















I have two elements, that are in two completely different parts of the DOM. And I'm trying to connect the two, so when you hover one element, the other one shows an effect.



The first element is in a component and is being displayed with code like this inside a component:



<button @mouseover="$emit( 'event-hovered', event.id )" @mouseout="$emit( 'event-not-hovered' )">
Button text
</button>


The second element is being generated using code from an AmCharts-demo:



createCustomMarker: function (image) {
var element = document.createElement('button');

element.className = 'map-marker the-id-' + image.id;
element.title = image.title;
element.style.position = 'absolute';
element.dataset.target = "#id" + image.id;
element.setAttribute('data-toggle', 'modal');

image.chart.chartDiv.appendChild(element);

return element;
}


As can be seen, then I've made a @mouseover that emits the id back to he main instance. In the main instance, then I have a method that finds the second element. But I do that using regular javascript, since I've had issues rewriting that createCustomMarker-function, so both Vue and AmCharts grasps what's going on. But this means that I can't add a class to the second elements (generated by createCustomMarker), the conventional v-model:class-way. I tried doing this in a method in the main instance:



eventHovered: function( elementId ){
let markerWithId = document.getElementById( 'id' + elementId );
markerWithId.classList.add("event-hovered");
console.log( markerWithId );
}


When I console.log the markerWithId, then I can see that that has the added class (event-hovered). But that doesn't appear on the screen, and I assume that's because Vue is controlling the DOM.



So how do I submit the element back to the DOM?
And is this a stupid way of doing this?










share|improve this question



























    0















    I have two elements, that are in two completely different parts of the DOM. And I'm trying to connect the two, so when you hover one element, the other one shows an effect.



    The first element is in a component and is being displayed with code like this inside a component:



    <button @mouseover="$emit( 'event-hovered', event.id )" @mouseout="$emit( 'event-not-hovered' )">
    Button text
    </button>


    The second element is being generated using code from an AmCharts-demo:



    createCustomMarker: function (image) {
    var element = document.createElement('button');

    element.className = 'map-marker the-id-' + image.id;
    element.title = image.title;
    element.style.position = 'absolute';
    element.dataset.target = "#id" + image.id;
    element.setAttribute('data-toggle', 'modal');

    image.chart.chartDiv.appendChild(element);

    return element;
    }


    As can be seen, then I've made a @mouseover that emits the id back to he main instance. In the main instance, then I have a method that finds the second element. But I do that using regular javascript, since I've had issues rewriting that createCustomMarker-function, so both Vue and AmCharts grasps what's going on. But this means that I can't add a class to the second elements (generated by createCustomMarker), the conventional v-model:class-way. I tried doing this in a method in the main instance:



    eventHovered: function( elementId ){
    let markerWithId = document.getElementById( 'id' + elementId );
    markerWithId.classList.add("event-hovered");
    console.log( markerWithId );
    }


    When I console.log the markerWithId, then I can see that that has the added class (event-hovered). But that doesn't appear on the screen, and I assume that's because Vue is controlling the DOM.



    So how do I submit the element back to the DOM?
    And is this a stupid way of doing this?










    share|improve this question

























      0












      0








      0








      I have two elements, that are in two completely different parts of the DOM. And I'm trying to connect the two, so when you hover one element, the other one shows an effect.



      The first element is in a component and is being displayed with code like this inside a component:



      <button @mouseover="$emit( 'event-hovered', event.id )" @mouseout="$emit( 'event-not-hovered' )">
      Button text
      </button>


      The second element is being generated using code from an AmCharts-demo:



      createCustomMarker: function (image) {
      var element = document.createElement('button');

      element.className = 'map-marker the-id-' + image.id;
      element.title = image.title;
      element.style.position = 'absolute';
      element.dataset.target = "#id" + image.id;
      element.setAttribute('data-toggle', 'modal');

      image.chart.chartDiv.appendChild(element);

      return element;
      }


      As can be seen, then I've made a @mouseover that emits the id back to he main instance. In the main instance, then I have a method that finds the second element. But I do that using regular javascript, since I've had issues rewriting that createCustomMarker-function, so both Vue and AmCharts grasps what's going on. But this means that I can't add a class to the second elements (generated by createCustomMarker), the conventional v-model:class-way. I tried doing this in a method in the main instance:



      eventHovered: function( elementId ){
      let markerWithId = document.getElementById( 'id' + elementId );
      markerWithId.classList.add("event-hovered");
      console.log( markerWithId );
      }


      When I console.log the markerWithId, then I can see that that has the added class (event-hovered). But that doesn't appear on the screen, and I assume that's because Vue is controlling the DOM.



      So how do I submit the element back to the DOM?
      And is this a stupid way of doing this?










      share|improve this question














      I have two elements, that are in two completely different parts of the DOM. And I'm trying to connect the two, so when you hover one element, the other one shows an effect.



      The first element is in a component and is being displayed with code like this inside a component:



      <button @mouseover="$emit( 'event-hovered', event.id )" @mouseout="$emit( 'event-not-hovered' )">
      Button text
      </button>


      The second element is being generated using code from an AmCharts-demo:



      createCustomMarker: function (image) {
      var element = document.createElement('button');

      element.className = 'map-marker the-id-' + image.id;
      element.title = image.title;
      element.style.position = 'absolute';
      element.dataset.target = "#id" + image.id;
      element.setAttribute('data-toggle', 'modal');

      image.chart.chartDiv.appendChild(element);

      return element;
      }


      As can be seen, then I've made a @mouseover that emits the id back to he main instance. In the main instance, then I have a method that finds the second element. But I do that using regular javascript, since I've had issues rewriting that createCustomMarker-function, so both Vue and AmCharts grasps what's going on. But this means that I can't add a class to the second elements (generated by createCustomMarker), the conventional v-model:class-way. I tried doing this in a method in the main instance:



      eventHovered: function( elementId ){
      let markerWithId = document.getElementById( 'id' + elementId );
      markerWithId.classList.add("event-hovered");
      console.log( markerWithId );
      }


      When I console.log the markerWithId, then I can see that that has the added class (event-hovered). But that doesn't appear on the screen, and I assume that's because Vue is controlling the DOM.



      So how do I submit the element back to the DOM?
      And is this a stupid way of doing this?







      javascript vue.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 3:33









      ZethZeth

      73511532




      73511532
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Try calling the validateNow() function after you edit the class on the marker.
          As seen here:
          https://docs.amcharts.com/3/javascriptcharts/AmCoordinateChart



          From the Docs:
          This method should be called after you changed one or more properties of any class. The chart will redraw after this method is called.Both attributes, validateData and skipEvents are optional (false by default).






          share|improve this answer


























          • Whenever I call that, my map-markers disappear (from the DOM as well). :-/

            – Zeth
            Nov 16 '18 at 5:04











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331030%2fvue-add-class-to-element-without-v-modelclass%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Try calling the validateNow() function after you edit the class on the marker.
          As seen here:
          https://docs.amcharts.com/3/javascriptcharts/AmCoordinateChart



          From the Docs:
          This method should be called after you changed one or more properties of any class. The chart will redraw after this method is called.Both attributes, validateData and skipEvents are optional (false by default).






          share|improve this answer


























          • Whenever I call that, my map-markers disappear (from the DOM as well). :-/

            – Zeth
            Nov 16 '18 at 5:04
















          0














          Try calling the validateNow() function after you edit the class on the marker.
          As seen here:
          https://docs.amcharts.com/3/javascriptcharts/AmCoordinateChart



          From the Docs:
          This method should be called after you changed one or more properties of any class. The chart will redraw after this method is called.Both attributes, validateData and skipEvents are optional (false by default).






          share|improve this answer


























          • Whenever I call that, my map-markers disappear (from the DOM as well). :-/

            – Zeth
            Nov 16 '18 at 5:04














          0












          0








          0







          Try calling the validateNow() function after you edit the class on the marker.
          As seen here:
          https://docs.amcharts.com/3/javascriptcharts/AmCoordinateChart



          From the Docs:
          This method should be called after you changed one or more properties of any class. The chart will redraw after this method is called.Both attributes, validateData and skipEvents are optional (false by default).






          share|improve this answer















          Try calling the validateNow() function after you edit the class on the marker.
          As seen here:
          https://docs.amcharts.com/3/javascriptcharts/AmCoordinateChart



          From the Docs:
          This method should be called after you changed one or more properties of any class. The chart will redraw after this method is called.Both attributes, validateData and skipEvents are optional (false by default).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 '18 at 3:52

























          answered Nov 16 '18 at 3:44









          RyanRyan

          950415




          950415













          • Whenever I call that, my map-markers disappear (from the DOM as well). :-/

            – Zeth
            Nov 16 '18 at 5:04



















          • Whenever I call that, my map-markers disappear (from the DOM as well). :-/

            – Zeth
            Nov 16 '18 at 5:04

















          Whenever I call that, my map-markers disappear (from the DOM as well). :-/

          – Zeth
          Nov 16 '18 at 5:04





          Whenever I call that, my map-markers disappear (from the DOM as well). :-/

          – Zeth
          Nov 16 '18 at 5:04




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331030%2fvue-add-class-to-element-without-v-modelclass%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine