yyyxxxI have the above structure for my html. I want to insert some content...">

Question about jQuery selector

<div id="foo">yyy<span>xxx</span></div>

I have the above structure for my html. I want to insert some content in yyy position. Can you tell me what will be a selector for him? I would pass this selector to some function and this function would execute$(selector).html('content')

+3
source share
5 answers
var s = $('#foo span');
$('#foo').text("hello").append(s);

Demo: http://jsfiddle.net/uTNTF/

Or, if updating HTML is an option, then just wrapping it yyyin <span>will make your life a lot easier:

$('#foo span:first-child').text("hello");

Demo: http://jsfiddle.net/uTNTF/1/

+6
source

jQuery . prepend() ( , , ):

$('#foo').prepend('some content');
+2

yyy , , , :

$('#foo').html($('#foo').html().replace('yyy','')).find('span').before('new content');

: http://jsfiddle.net/MTu6c/

+1

, , , .

"yyy" " ", - :

$('#foo').html('some content' + $('#foo span').html())
0

"yyy" ​​ DOM node. jQuery - , DOM .

See here (your question may be seen as a duplicate of this): How to select text nodes using jQuery?

0
source

All Articles