Sleek Geek Sleek Geek - 11 months ago 60
jQuery Question

Do something when div content changes to a given value

I am Trying to do something when the content of a DIV changes to an "O", but it does not seem to work for me.

My code looks like below. Any Ideas on how I can solve this problem :

jQuery('.select2-chosen').bind('DOMSubtreeModified', function(event)
var newText = $(this).text();
if($('.select2-chosen:contains("O")').length === 1)

The issue is on the inches field on this page

Answer Source

Working Example.

Why not just using change() event since select-2 will triggers the standard DOM event, so try :

$('#SPECIFIC_ID').on('change', function() {
____^^^^^^^^^^^  //Don't forget to change the id with yours

    var selected_text = $('option:selected', this).text();

    if( selected_text == "O" ){
         alert('the selected value is O');

Hope this helps.