Question: JQuery function doesn't fire in ejs

Question

JQuery function doesn't fire in ejs

Answers 2
Added at 2017-11-30 22:11
Tags
Question
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
    alert( "ready!" );
    $('#dropDown').click(function() {
    console.log("run");
    var selected = $('#dropDown').find(":selected").text();
    console.log(selected);
    });
});

</script>

<div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">
                    <center>Benchmark Usage</center>
                </h1>
            </div>
            <!-- /.col-lg-12 -->
  </div>
<div class="row" data-ng-controller="">
<div class="col-md-12">

<select id="dropDown">
<option value="day">every day</option>
<option value="minute">every minute</option>
</select>

<iframe src="http://vgzeburt55:5601/goto/517982d9d05378bac8368b4bf91338fe?embed=true" height="710" width="100%"></iframe>
</div>
</div>

I was trying to get selected text through jquery. However, even the ready alert doesn't show up. Am I missing something? Also, am I trying to get the selected text in the correct way?

Answers to

JQuery function doesn&#39;t fire in ejs

nr: #1 dodano: 2017-11-30 22:11

Bind on('change' event.

Working example:

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
    alert( "ready!" );
    
    $('#dropDown').on('change', function() {
      alert( this.value );
      console.log("run");
    var selected = this.value;
    console.log(selected);
    })

    
});

</script>

<div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">
                    <center>Benchmark Usage</center>
                </h1>
            </div>
            <!-- /.col-lg-12 -->
  </div>
<div class="row" data-ng-controller="">
<div class="col-md-12">

<select id="dropDown">
<option value="day">every day</option>
<option value="minute">every minute</option>
</select>

<iframe src="http://vgzeburt55:5601/goto/517982d9d05378bac8368b4bf91338fe?embed=true" height="710" width="100%"></iframe>
</div>
</div>

nr: #2 dodano: 2017-11-30 22:11

Shouldn't your jquery src have https: prefix?

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Source Show
◀ Wstecz