I have 2 paragraphs like this :
<p>text bla bla bla owner of the idea : John Smith</p>
<p>text bla bla bla bla bla bla owner of the idea : James Marino</p>
Is there any way I could use jQuery to add a new line before "Owner of the idea" till the end of the sentence?
Thanks in advance
If this is a copy of your jquery script, try using a \n
for new line. That work in javascripts.
jQuery WORKING example:
<p id="s">text bla bla bla owner of the idea : John Smith</p>
<p>text bla bla bla bla bla bla owner of the idea : James Marino</p>
<script type="text/javascript">
$(document).ready(function() {
$("p").each(function() {
var getContent=$(this).text();
var newString=getContent.replace('owner of the idea','<br />owner of the idea');
$(this).html(newString);
});
});
</script>
If the pattern is consistent, you could do a replace based on the :
character.
$('p').each(function(){
this.html(this.html().replace(":",":<br />"));
});
Update
According to the comment, it looks like I misread the question. You can still use this same strategy however,
var p = $('p:first');
p.html(p.html().replace("owner of the idea", "<br />owner of the idea"));
$('<br />').insertBefore(selector for your paragraph);
I don't know what your surrounding markup looks like, so it's not clear what the best selector for your paragraph would be.
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