Javascript

Dear All,

How to know which line of the Javascript that html will use?
arkam chouAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.