jQuery javascript regex Replace br tag with \n

by in , , 0

var str = document.getElementById('mydiv').innerHTML;
document.getElementById('mytextarea').innerHTML = str.replace(/<br\s*[\/]?>/gi, "\n");
or using jQuery:
var str = $("#mydiv").html();
var regex = /<br\s*[\/]?>/gi;
$("#mydiv").html(str.replace(regex, "\n"));
edit: added i flag
edit2: you can use /<br[^>]*>/gi wich will match anything between the br and slash if you have for example <br />

Source:

jQuery javascript regex Replace <br> with \n

disable selected options by jQuery

by in , 0

This will disable/enable the options when you select/remove them, respectively.
$("#theSelect").change(function(){          
    var value = $(this).val();
    if (value === '') return;
    var theDiv = $(".is" + value);

    var option = $("option[value='" + value + "']", this);
    option.attr("disabled","disabled");

    theDiv.slideDown().removeClass("hidden");
    theDiv.find('a').data("option",option);
});


$("div a.remove").click(function () {     
    $(this).parent().slideUp(function() { $(this).addClass("hidden"); });
    $(this).data("option").removeAttr('disabled');
});
Source: 
jQuery - disable selected options