• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

Javascript

Dear All,

How to know which line of the Javascript that html will use?
0
arkam chou
Asked:
arkam chou
  • 7
  • 5
  • 2
  • +1
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
You have not given us any information that we can use to answer your question.  Do you have some code that you are trying to figure out?  Please post it if you do.
0
 
arkam chouAuthor Commented:
example for this code: https://www.datatables.net/examples/api/add_row.html

I want to which line of javascript is use in button "Add new row, serach" and label "showing ..entries, Previous.. Next"
0
 
Jeff DarlingDeveloper AnalystCommented:
Those jQuery examples does not include that in the HTML sample.

Here is a small sample that works based on the sample snippets.

Notice line 15 is the button with the ID addRow to add the row.

<!DOCTYPE html>
<html lang="en">
  <head>
      <!-- jQuery -->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
      <!-- dataTables -->
    <script src="http://cdn.datatables.net/1.10.5/js/jquery.dataTables.min.js"></script>

    <link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.5/css/jquery.dataTables.css">
    <title>DATATABLE SAMPLE</title>

  </head>
  <body>

  <button id="addRow">Add Row</button>
<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Column 1</th>
                <th>Column 2</th>
                <th>Column 3</th>
                <th>Column 4</th>
                <th>Column 5</th>
            </tr>
        </thead>

        <tfoot>
            <tr>
                <th>Column 1</th>
                <th>Column 2</th>
                <th>Column 3</th>
                <th>Column 4</th>
                <th>Column 5</th>
            </tr>
        </tfoot>
    </table>

      <script>
  $(document).ready(function() {
    var t = $('#example').DataTable();
    var counter = 1;

    $('#addRow').on( 'click', function () {
        t.row.add( [
            counter +'.1',
            counter +'.2',
            counter +'.3',
            counter +'.4',
            counter +'.5'
        ] ).draw();

        counter++;
    } );

    // Automatically add a first row of data
    $('#addRow').click();
} );
  </script>


  </body>
</html>

Open in new window

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
arkam chouAuthor Commented:
thank Jeff Darling,

I will test it. how can I know which line of javascript that html above will load. in Javascript there has a lot of code, it is difference for starter like me to understand. so any tool that can help know the process step by step like visual basic.
0
 
Jeff DarlingDeveloper AnalystCommented:
The jQuery and the dataTables javascript files are libraries.  You do not modify them, just include them.

If you are new, check out jsfiddle.  

Here is a jsfiddle similar to the example above.
0
 
arkam chouAuthor Commented:
Thanks Jeff Darling,

The goal of this code is using current code that having and add some feature to it like below:
1. can delete and update row
2. transfer all data in table to MySQL
0
 
Michel PlungjanIT ExpertCommented:
@Jeff: I suggest not to pollute the body with script that lives happily in the head of the page.I strive to show new javascripters as clean code as possible so they do not pick up poor habits.
0
 
arkam chouAuthor Commented:
How to know which line of the Javascript that html will use?
0
 
Michel PlungjanIT ExpertCommented:
If the event handlers are using ID then the tag with the ID. If class then class, if selector then whatever the selector is covering. Again your question is too vague to answer precisely.
0
 
arkam chouAuthor Commented:
ex: I buy web application from someone. the web have a lot of javascript, so I want to know which line or scope of code will be process when I click on it or mouse over it.
0
 
Michel PlungjanIT ExpertCommented:
Run a debugger, for example Chrome's developer tools
0
 
arkam chouAuthor Commented:
it is good for using Chrome's develper tool but how to know which part of code will be process when click on something.
0
 
Michel PlungjanIT ExpertCommented:
I am still not sure in what circumstance you need to know.

Here is a way to interrogate objects

var elem = document.querySelector("someselector"), handlers=[];
for (var prop in elem) { // for each property
  if (prop.indexOf("on") ==0)  {  // event handlers starts with "on" 
   handlers.push(prop);  
  }
  window.console && console.log(handlers);  
}

Open in new window

0
 
arkam chouAuthor Commented:
Dear Michel Plungjan,
I know code and how to use it a little. for your code, look like it can track the process of code. where should I use it?
0
 
Michel PlungjanIT ExpertCommented:
Anywhere. You need to plug in the selector of the tag you want to track
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now