html - jQuery: Using the right selector and method to change some text? -
I want to change the text where it stands "2 days ago" using jQuery.
html:
& lt; Div id = "post_id_136_row" class = "post_row row" & gt; & Lt; Div id = "post_id_136" class = "post_column col-xs-12 col-sm-offset-2 col-sm-8 colmd-offset-3 col-md-6 col-lg-offset-4 col- LG-4" & Gt; & Lt; Div class = "inner_post_row line" & gt; & Lt; Div id = "thumbnail_column" class = "col-xs-4 col-sm-4 col-md-4 col-lg-3" & gt; & Lt; / Div & gt; & Lt; Div class = "title col-xs-8 col-sm-8 col-md-8 col-lg-9" & gt; & Lt; Span id = "post_title" & gt; & Lt; / Span & gt; & Lt; Br> & Lt; / Br & gt; & Lt; Span id = "time_added" & gt; 2 days ago & lt; An id = "edit_post_136" class = "edit_post" href = "#" & gt; & Lt; / A & gt; & Lt; / Span & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;
jQuery: (I tried it, but it does not work)
$ ('.' Post_row Div div div span ') [1] .replaceWith (' 4 days ago '));
Any suggestions? First of all, you will need to make sure that if you want "time_ added" an id or class (
Class if you have more than one line, I think you are).
If this is your only one, use the ID automatically:
$ ('# time_added'). Html ('4 days ago');
Otherwise, you can use find ()
:
$ ('.post_row'). ('. Time_added') .html ('4 days ago');
Comments
Post a Comment