jquery contains method to look for a paragraph tag

Posted on 2016-10-19
Last Modified: 2016-10-19
Hi experts,

I have this fiddle

it looks like this:
In this fiddle i'm doing this:

// look for all elements using this class DivStyle1 and append the image to the one that contains this string Div 3
$('.DivStyle1:contains("Div 3")').append(img);  

That works fine.

How do i revise it, so it instead of looking for this string "Div 3"  I look for the <p> tag instead.

I tried this but it didn't see to work:

// look for all elements using this class DivStyle1 and append the image to the one that contains this tag <p>

Any ideas of what I'm doing wrong?
Question by:maqskywalker

Accepted Solution

Thomas Wheeler earned 500 total points
Comment Utility
This is one way

Open in new window

 $('.DivStyle1>p:contains("Div 3")').append(img);   

Open in new window


Author Closing Comment

Comment Utility

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to dynamically set the form action using jQuery.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now