Note that there are some explanatory texts on larger screens.

plurals
  1. POSimplifying jQuery events
    text
    copied!<p>I wrote these functions to handle data when a particular cell of my table is clicked. I have 6 functions that handle the data for the event but each are the same, they just with a different ID. Here is my code:</p> <pre><code> //COMMENT HANDLING $("#mondayCommentLink").click(function () { var mondayhtmls = $("#mondayComment"); var input = $("&lt;input type='text' id='mondayCommentText' name='mondayCommentText' size='10' /&gt;"); input.val(data.days[0].comment); mondayhtmls.html(input); }); $("#tuesdayCommentLink").click(function () { var tuesdayhtmls = $("#tuesdayComment"); var inputt = $("&lt;input type='text' id='tuesdayCommentText' name='tuesdayCommentText' size='10' /&gt;"); inputt.val(data.days[1].comment); tuesdayhtmls.html(inputt); }); $("#wednesdayCommentLink").click(function () { var htmls = $("#wednesdayComment"); var input = $("&lt;input type='text' id='wednesdayCommentText' name='wednesdayCommentText' size='10' /&gt;"); input.val(data.days[2].comment); htmls.html(input); }); $("#thursdayCommentLink").click(function () { var htmls = $("#thursdayComment"); var input = $("&lt;input type='text' id='thursdayCommentText' name='thursdayCommentText' size='10' /&gt;"); input.val(data.days[3].comment); htmls.html(input); }); $("#fridayCommentLink").click(function () { var htmls = $("#fridayComment"); var input = $("&lt;input type='text' id='fridayCommentText' name='fridayCommentText' size='10' /&gt;"); input.val(data.days[4].comment); htmls.html(input); }); $("#saturdayCommentLink").click(function () { var htmls = $("#saturdayComment"); var input = $("&lt;input type='text' id='saturdayCommentText' name='saturdayCommentText' size='10' /&gt;"); input.val(data.days[5].comment); htmls.html(input); }); </code></pre> <p>Is there a way I can simply this code or make it more elegant than having 6 separate functions handling each specific cell event?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload