Java Script code
$("#category select").change(function(){
var category = $('select option:selected').html();
$.ajax({
type:"Post",
url:"collectiepost.php",
data:"category="+category,
cache:"false",
success:function(html){
$("select").html(html).find("option .category");
}
});
});
});
html output on that page collectiepost.php
<select id="ontwerper">
<option class="desinger">vikas</option>
</select>
<select id="category">
<option class="category">cloth1</option>
<option class="category">cloth2</option>
</select>
i want to extract only that part of html
need output
<select>
<option class="category">cloth1</option>
<option class="category">cloth2</option>
</select>
problem
but my code showing all option tag like that
<select>
<option class="desinger">vikas</option>
<option class="category">cloth1</option>
<option class="category">cloth2</option>
</select>
This line:
Will set the content of the
selectelement tohtml, and then callfindbut do nothing with the result. You need to reduce the HTML fragment returned by your AJAX call before adding it to the DOM:Here’s a working example. Notice that there is no space between
optionand.category. Your current selector will match.categoryelements that are descendants ofoptionelements.