I have this perfectly working two jQuery functions, and I need to pass parameter to it, as I need to call these functions multiple times with different parameters.
$('#link-31').click(function() {
$(document.getElementById('row-31')).css("background-color", "#B3B3FF");
$(document.getElementById('row-31')).css("border", "#0000FF");
});
$(document).on('click', function(e) {
if (!$(e.target).closest('#link-31').length) {
$('#row-31').css("background-color", '');
$('#row-31').css("border", '');
}
});
In the above code "link-31" and "row-31" are id of two html components. These are the two values that I need to pass as parameters. So how can this be done?
Thanks in advance.
The first function is executed on click of link(i.e. tag) with id="link-31", that highlights a table row(i.e. tag) with id="row-31".
The second function is executed by clicking anywhere on the page other than the highlighted row that removes the highlighting.
Now there are assume 'n' number of links that are to be used for highlighting 'n' number of rows, in this case only the link id and row id will change in the above code.
Below is the part of html file that is affected by the above code.
<body>
<ul class="sidebar-nav" style="padding-top: 70px">
<nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix col-sm-3">
<li id="link-1" class="list-group-item"><a href="#data-1" class="scroll">1</a></li>
<li id="link-2" class="list-group-item"><a href="#data-2" class="scroll">2</a></li>
<li id="link-3" class="list-group-item"><a href="#data-3" class="scroll">3</a></li>
.
.
.
<li id="link-31" class="list-group-item"><a href="#data-31" class="scroll">31</a></li>
<li id="link-32" class="list-group-item"><a href="#data-32" class="scroll">32</a></li>
</nav>
</ul>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<tr id="row-1">
<th scope="row"><a id="data-1" class="scroll">1</a></th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr id="row-2">
<th scope="row"><a id="data-2" class="scroll">2</a></th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
.
.
.
<tr id="row-32">
<th scope="row"><a id="data-32" class="scroll">32</a></th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>