0

https://jsfiddle.net/doksul/1mc0y33k/

When i click submit button, change html a tag But jquery change event didn't catch this.

How do I get change html a tag text changed?

$('#aTag').change(function() {
  $('#textReulst').val('changed');
});

$('#submit').click(function() {
  $('#aTag').html('123');
});
Hulk Choi
  • 1,067
  • 2
  • 8
  • 12

7 Answers7

3

Hello Please use following code, trigger your change event after clicking on submit:

$('#aTag').change(function() {
   $('#textReulst').val('changed');
});

$('#submit').click(function() {
   $('#aTag').html('123');
   $("#aTag").trigger("change");
});

Use this JS Fiddle URL : https://jsfiddle.net/1mc0y33k/3/

Jyoti Sharma
  • 994
  • 5
  • 12
0

i did a fiddle, thing is you need to trigger the change event on anchor tag, like this.

 $('#aTag').trigger('change');
Siddharth
  • 859
  • 8
  • 16
0
function txtchange(){
  $('#textReulst').val('changed');
}

$('#submit').click(function() {

    $('#aTag').html('2222');
    txtchange();
});
Muhammad Atif
  • 1,050
  • 1
  • 9
  • 21
0

you need to trigger your .change function.

$('#aTag').change(function() {
  $('#textReulst').val('changed');
});

$('#submit').click(function() {
    $('#aTag').html('123');
    $( "#aTag" ).change();
});
Manu S
  • 173
  • 11
0

.change() event is limited to [input] elements, [textarea] boxes and [select] elements. For [select], [input:type=checkbox], and [input:type=radio] buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.

I guess you are bind change event to other type of elements, you need manually trigger event after innerHtml changes.

Chonchol Mahmud
  • 2,717
  • 7
  • 39
  • 72
lee
  • 111
  • 3
0

You have to use a jquery trigger api for the functionality you want.

For that you can create a new custom jquery Api like as below

jQuery.fn.htmlChange = function (new_html) {
    $(this).html(new_html);
    $(this).trigger('change');
};

and calling the above Api when you need to trigger the change event whenever the markup is updated.

You can call the above function like below

$('#aTag').htmlChange('123');

Here is the working sample FIDDLE

Hope it works for you.

Mayank
  • 1,351
  • 5
  • 23
  • 42
-1

Here i do not use trigger take a look UPADATED : JSFIDDLE

Hope this is help you.Use trigger for your result. JSFiddle

Add this:

  $('#aTag').change(function() {
  $('#submit').val('changed');
});

  $('#textReulst').click(function() {
  $('#aTag').html('123');
});
Chonchol Mahmud
  • 2,717
  • 7
  • 39
  • 72
  • thank you for your answer but i think trigger is not best answer. :( if any other side change html must be get in code trigger. how do i better code this? – Hulk Choi Jan 07 '16 at 05:57