replace content via jquery
I'm new to jquery and have a simple question for you. How to replace ".5" with ":30" in the below shown html "div" by using jquery?
<div class="timepicker"> <select> <option value="0" selected="selected">00</option> <option value="0.5">00.5</option><option value="1">01</option> <option value="1.5">01.5</option><opti开发者_运维知识库on value="2">02</option> </select> </div>
Thanks in advance.
You could do (this works for the html, do you need the valuies too?):
$('option:contains(".5")').each(function(){
$(this).html($(this).html().replace('.5', ':30'));
});
if you also need to replace the values:
$('option:contains(".5")').each(function(){
$(this).html($(this).html().replace('.5', ':30'));
$(this).val($(this).val().replace('.5', ':30'));
});
fiddle here: http://jsfiddle.net/nicolapeluchetti/dwWXs/
$('option[value="0.5"]').attr("value",".30");
$('option[value="0.5"]').html(".30");
精彩评论