Link to home
Start Free TrialLog in
Avatar of adworldmedia
adworldmediaFlag for United States of America

asked on

Javascript Open Wizard on click event from dynamic data

With some C# code, I'm building a Table including a <DIV> tag that I've added a value to that refers to an object ID.

The table will have multiple rows, each having a different object ID, and its own unique <DIV> tag, ie:

<table>
  <tr>
  <th>Function</th>
  <th>Name</th>
  <th>ID</th>
  </tr>
  <tr>
    <td><div id='edit' value='1234'>Edit</div></td>
    <td>Object One</td>
    <td>1234</td>
  </tr>
  <tr>
    <td><div id='edit' value='1235'>Edit</div></td>
    <td>Object two</td>
    <td>1235</td>
  </tr>

Open in new window


I want to be able to use Jquery or Javascript to retrieve the value of which DIV was clicked...  How would I do that?

    var wizard = $("#campaignWizard").wizard();
    $("#edit").click(function () {
        var clickedID = {????};
        wizard.show();
    });

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

ID attribute MUST be unique in a document.
In you case use a class instead.

Test page : http://jsfiddle.net/bkjb1u9t/1/

For teh sake of your question, use :
var wizard = $("#campaignWizard").wizard();
    $("div[id='edit']").click(function () { //  if you change it to a class use : $("div.edit")
        var myCell = $(this).closest("td"); 
        var nextTD1 = myCell.next();
        var nextTD2 = nextTD1.next();
        alert( nextTD1.text() );
        alert( nextTD2.text() );
        wizard.show();
    });

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
from julianH code, you should read, line 8, data-id instead data-d
@leakim - thanks for catching that