change the id
of each <li>
to include the id that you want to pass into the showQ
function. in the document ready handler assign a click hander to the <li>
elements and call the showQ
function from there, passing in the id extracted from the clicked <li>
. in the click handler refer to the clicked <li>
using $(this)
in order to add a class to it
html
<ul>
<li id="i0001">Q 1</li>
<li id="i0002">Q 2</li>
<li id="i0003">Q 3</li>
<li id="i0004">Q 4</li>
</ul>
javascript
function showQ(id) {
$('#' + id).show();
}
$(document).ready(function() {
$("ul li").click(function() {
var id = $(this).attr("id").substring(1);
showQ(id);
$(this).addClass("some_css_clas");
});
});