Click me!and I see this warning, but I want to call a function inside this oncli...">

Div call function

I do this: <div onclick='alert("xxx")'>Click me!</div>and I see this warning, but I want to call a function inside this onclick. I am trying to do this, but it does not work.

  function GetContent(prm){
    alert(prm);
  }

  <div onclick='GetContent("xxx")'>Click me!</div>

I need to call this inline function so as not to assign an id or class to this div and use jquery. What's the solution? Thanks

+3
source share
2 answers

Using code inlineis bad practice, you need to assign IDeither Classdiv and call functions, for example:

<div class="test">Click me!</div>

$('div.test').click(function(){
    GetContent("xxx");
});

.

I need to call this inline function not to assign an id or class to this div and use jquery.

I think you are already doing this with this code:

<div onclick='GetContent("xxx")'>Click me!</div>

inline id . , , .

+16

div , -

$("div.myclass").click(function(){
    GetContent("xxx");
});

<div class="myclass"></div>

click div myclass.

, id div.

+5

Source: https://habr.com/ru/post/1736460/


All Articles