JQuery/Javascript functions with dynamics id









up vote
0
down vote

favorite












I'm in this situation, where I have a div and a button:






<div style="display:none" class="partita" onkeypress="editPartita(e,???????)" >
...
</div>
<button id="plusPartite"></button>





Onclick of this button there is another function:






function ShowNewPartite(i) 
var a = document.getElementsByClassName("partita");
a[0].style.display = 'unset';
var newI = parseInt(i) + 1;
var newId = "partita" + newI ;
a[0].setAttribute("id", newId);





that assign an dinamic id on div and I want that if the user keypress on the div "partita",there is another function that is:






editPartita(e,id)
if(e.which == 13)

...





that save on DB the elements.
How I call back the id that is created in a ShowNewPartite(i) for a new div "partita",in the function editPartita(e,??) ?
Thankyou










share|improve this question



















  • 3




    Don't dynamically change an id. You can use data-attributes developer.mozilla.org/en-US/docs/Learn/HTML/Howto/… instead. Don't ever mess with an element's id once you set it and don't ever have two elements that share an id in the same scope of an application.
    – zfrisch
    Nov 9 at 20:20







  • 6




    If you create snippets, make sure it makes sense to run them.
    – connexo
    Nov 9 at 20:26










  • Setup the onkeypress handler from JavaScript using Element.prototype.addEventListener
    – Aluan Haddad
    Nov 9 at 20:31















up vote
0
down vote

favorite












I'm in this situation, where I have a div and a button:






<div style="display:none" class="partita" onkeypress="editPartita(e,???????)" >
...
</div>
<button id="plusPartite"></button>





Onclick of this button there is another function:






function ShowNewPartite(i) 
var a = document.getElementsByClassName("partita");
a[0].style.display = 'unset';
var newI = parseInt(i) + 1;
var newId = "partita" + newI ;
a[0].setAttribute("id", newId);





that assign an dinamic id on div and I want that if the user keypress on the div "partita",there is another function that is:






editPartita(e,id)
if(e.which == 13)

...





that save on DB the elements.
How I call back the id that is created in a ShowNewPartite(i) for a new div "partita",in the function editPartita(e,??) ?
Thankyou










share|improve this question



















  • 3




    Don't dynamically change an id. You can use data-attributes developer.mozilla.org/en-US/docs/Learn/HTML/Howto/… instead. Don't ever mess with an element's id once you set it and don't ever have two elements that share an id in the same scope of an application.
    – zfrisch
    Nov 9 at 20:20







  • 6




    If you create snippets, make sure it makes sense to run them.
    – connexo
    Nov 9 at 20:26










  • Setup the onkeypress handler from JavaScript using Element.prototype.addEventListener
    – Aluan Haddad
    Nov 9 at 20:31













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm in this situation, where I have a div and a button:






<div style="display:none" class="partita" onkeypress="editPartita(e,???????)" >
...
</div>
<button id="plusPartite"></button>





Onclick of this button there is another function:






function ShowNewPartite(i) 
var a = document.getElementsByClassName("partita");
a[0].style.display = 'unset';
var newI = parseInt(i) + 1;
var newId = "partita" + newI ;
a[0].setAttribute("id", newId);





that assign an dinamic id on div and I want that if the user keypress on the div "partita",there is another function that is:






editPartita(e,id)
if(e.which == 13)

...





that save on DB the elements.
How I call back the id that is created in a ShowNewPartite(i) for a new div "partita",in the function editPartita(e,??) ?
Thankyou










share|improve this question















I'm in this situation, where I have a div and a button:






<div style="display:none" class="partita" onkeypress="editPartita(e,???????)" >
...
</div>
<button id="plusPartite"></button>





Onclick of this button there is another function:






function ShowNewPartite(i) 
var a = document.getElementsByClassName("partita");
a[0].style.display = 'unset';
var newI = parseInt(i) + 1;
var newId = "partita" + newI ;
a[0].setAttribute("id", newId);





that assign an dinamic id on div and I want that if the user keypress on the div "partita",there is another function that is:






editPartita(e,id)
if(e.which == 13)

...





that save on DB the elements.
How I call back the id that is created in a ShowNewPartite(i) for a new div "partita",in the function editPartita(e,??) ?
Thankyou






<div style="display:none" class="partita" onkeypress="editPartita(e,???????)" >
...
</div>
<button id="plusPartite"></button>





<div style="display:none" class="partita" onkeypress="editPartita(e,???????)" >
...
</div>
<button id="plusPartite"></button>





function ShowNewPartite(i) 
var a = document.getElementsByClassName("partita");
a[0].style.display = 'unset';
var newI = parseInt(i) + 1;
var newId = "partita" + newI ;
a[0].setAttribute("id", newId);





function ShowNewPartite(i) 
var a = document.getElementsByClassName("partita");
a[0].style.display = 'unset';
var newI = parseInt(i) + 1;
var newId = "partita" + newI ;
a[0].setAttribute("id", newId);





editPartita(e,id)
if(e.which == 13)

...





editPartita(e,id)
if(e.which == 13)

...






javascript html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 20:52









Barmar

413k34237339




413k34237339










asked Nov 9 at 20:12









user10276822

43




43







  • 3




    Don't dynamically change an id. You can use data-attributes developer.mozilla.org/en-US/docs/Learn/HTML/Howto/… instead. Don't ever mess with an element's id once you set it and don't ever have two elements that share an id in the same scope of an application.
    – zfrisch
    Nov 9 at 20:20







  • 6




    If you create snippets, make sure it makes sense to run them.
    – connexo
    Nov 9 at 20:26










  • Setup the onkeypress handler from JavaScript using Element.prototype.addEventListener
    – Aluan Haddad
    Nov 9 at 20:31













  • 3




    Don't dynamically change an id. You can use data-attributes developer.mozilla.org/en-US/docs/Learn/HTML/Howto/… instead. Don't ever mess with an element's id once you set it and don't ever have two elements that share an id in the same scope of an application.
    – zfrisch
    Nov 9 at 20:20







  • 6




    If you create snippets, make sure it makes sense to run them.
    – connexo
    Nov 9 at 20:26










  • Setup the onkeypress handler from JavaScript using Element.prototype.addEventListener
    – Aluan Haddad
    Nov 9 at 20:31








3




3




Don't dynamically change an id. You can use data-attributes developer.mozilla.org/en-US/docs/Learn/HTML/Howto/… instead. Don't ever mess with an element's id once you set it and don't ever have two elements that share an id in the same scope of an application.
– zfrisch
Nov 9 at 20:20





Don't dynamically change an id. You can use data-attributes developer.mozilla.org/en-US/docs/Learn/HTML/Howto/… instead. Don't ever mess with an element's id once you set it and don't ever have two elements that share an id in the same scope of an application.
– zfrisch
Nov 9 at 20:20





6




6




If you create snippets, make sure it makes sense to run them.
– connexo
Nov 9 at 20:26




If you create snippets, make sure it makes sense to run them.
– connexo
Nov 9 at 20:26












Setup the onkeypress handler from JavaScript using Element.prototype.addEventListener
– Aluan Haddad
Nov 9 at 20:31





Setup the onkeypress handler from JavaScript using Element.prototype.addEventListener
– Aluan Haddad
Nov 9 at 20:31


















active

oldest

votes











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',
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%2f53232699%2fjquery-javascript-functions-with-dynamics-id%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232699%2fjquery-javascript-functions-with-dynamics-id%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

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo