javascript - Replace Div content with jQuery/AJAX - with button ID -


I'm building a website that's like a "Choose your Adventure" type game. On the page there will be a question with three different options (in the form of buttons) for the user when they click on the button, the jQuery and AJAX questions will replace the text with a different HTML file with a new question. All buttons will also be changed and written in that different HTML file.

My problem is that I need to keep my ID number for each button so that when requesting to change the question jquery to the query that goes to a specific file, which has a new question That matches the ID number on the button. So each button has an ID that matches the new question.

In short: Is there a way to get an ID or data attribute from the clicked button, and pass it in my jQuery / AJAX function? Thanks!

"Is there a way to retrieve an ID or data attribute from the clicked button, Is this information in my jQuery / AJAX function? "

There are a few ways you can do this: Here is one of the easiest ways:

  & lt ; Div class = "button" id = "button1" & gt; Click me & lt; / Div & gt; Var click = ''; $ ('.button'). Click (function () {clicked = $ (this) .attr ('id'); window.alert ('you clicked:' + clicked);});  

This is the one to display.


Comments