I have a div that will appear on the page at a separate point. It doesn't always appear on the page and can be added via a CMS if needed. There's a line of text that will appear within the body. If the user has decided to have this div added, it would need to be moved into position via jquery. So, I have this text:
<p><strong>Key Facts:</strong></p>
I want to find it using jquery, then move the other div in front of it. I tried a couple of different ways to select this text then move the div in front of it and haven't had any luck. The best way I found to find the text was to do this:
var foundin = $('*:contains("<p><strong>Key Facts:</strong></p>")');
From that point, to move the div into position, I thought I could something like this:
$('#DivIWantToMove').insertBefore($foundin);
That didn't work, though. I also looked at this:
$( $foundin ).before( $('#DivIWantToMove') );
AS you might imagine, since you're reading this, that didn't work either. So, I'm asking you, is it possible to do what I want? I'm fairly constrained by the CMS that we are using. The DIV I need to move will always be someplace on the page and I have to move it. The client doesn't want to have to add a class to <p><strong>Key Facts:</strong></p>
so I'm let with this. If I could have a class on <p>
then it would be super easy. I've already done it. The client doesn't like having an extra step. Any ideas?
dynamically whenever the given condition met?
– Amit Garg Nov 05 '13 at 04:22` initially, it's a cakewalk to move the div in front of it. But, as it stands now, I can select the paragraph, but moving the div in front of it doesn't work. If I add a class to the `
` dynamically, would that do the trick you think? I tried an experiment on this page here and it doesn't seem to work. :(
– Jason Shultz Nov 05 '13 at 04:31` tag too?
– charlietfl Nov 05 '13 at 05:01