<div id="foo">yyy<span>xxx</span></div>
I have the the above structure for my html. I want to insert some content at yyy position. Can you let me know what will be the selector for it?
I would pass that selector to somefunction and that function will do $(selector).html('content')
var s = $('#foo span');
$('#foo').text("hello").append(s);
Demo: http://jsfiddle.net/uTNTF/
Or, if updating the HTML is an option, then simply wrapping yyy in a <span> will make your life a lot simpler:
$('#foo span:first-child').text("hello");
Demo: http://jsfiddle.net/uTNTF/1/
You can use jQuery .prepend() function (insert content, specified by the parameter, to the beginning of each element in the set of matched elements):
$('#foo').prepend('some content');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With