Reputation: 1530
i have variable for index++
var folderIndex = 1;
let currentFolderIndex = folderIndex++;
i want to call table ID into my onclick .
<table id="tableAudience' + currentFolderIndex + '" ></table>
<div onclick="openFolder(event, 'howTocall table ID in here')" ></div>
How to do it?
i dont know how to set my id because there will be a conflict of quotes
onclick="openFolder(event, 'howTocall table ID in here')"
Image of my Code : http://prntscr.com/h82axw
I'm not use JSFiddle because I only use js and css files.
Thx before.
Upvotes: 2
Views: 155
Reputation: 1792
You can call the onCLick Without worrying about the ID
<table id="tableAudience1" > </table>
<div onclick="openFolder(event,this)"> First Table </div>
and on the onclick function you can detect the ID using this
function openFolder(event,item){
// will give you the table ID
console.log( $(item).prev().attr("id"));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="tableAudience1" > </table>
<div onclick="openFolder(event,this)"> First Table </div>
<br/>
<table id="tableAudience2" > </table>
<div onclick="openFolder(event,this)"> Second Table </div>
<br/>
<table id="tableAudience3" > </table>
<div onclick="openFolder(event,this)"> Third Table </div>
<br/>
<table id="tableAudience4" > </table>
<div onclick="openFolder(event,this)"> Fourth Table </div>
Upvotes: 2