Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

jQuery Selector Question

Posted on 2016-09-22
7
Medium Priority
?
77 Views
Last Modified: 2016-09-24
I am trying to find a jQuery command to retrieve an DIV whose Class ends in MyTarget.  So far I haven't found an example which works.
0
Comment
Question by:Howard Bash
7 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 1000 total points
ID: 41811825
This seems to work:
$("div[class$='MyTarget']")

Open in new window

0
 
LVL 22

Expert Comment

by:Mrunal
ID: 41811984
Here is the list of all types of selectors:

https://api.jquery.com/category/selectors/
0
 
LVL 1

Author Comment

by:Howard Bash
ID: 41812366
I tried the following on a SharePoint page:  $("div[class$='RootAspMenu']").length

The returned value was 0.  I use the length to check if the selector returned an object.

Also,  I searched the DOM view and found the div tag with a class = 'wxyZ_RootAspMenu'

If I look for that using $('#wxyZ_RootAspMenu').length I get back the value 1.

Please not that the prefix (wxyZ) changes which is why I need the kind of selecting.

IMPORTANT!!!
I realize that that value is the id value not the class and tried  $("div[id$='RootAspMenu']").length which also returned 0.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Expert Comment

by:Julian Hansen
ID: 41812453
This works for me
<!doctype html>
<html>
<title>Selector Test</title>
<head>
</head>
<body>
<div class="'wxyZ_RootAspMenu"></div>
<script src="http://code.jquery.com/jquery.js"></script>
<script>
$(function() {
	var x = $('div[class$="RootAspMenu"]');
	console.log(x.length);
});
</script>
</body>
</html>

Open in new window

Are you sure there are no errors in the console that might be preventing the code from running?
0
 
LVL 1

Author Comment

by:Howard Bash
ID: 41812570
What if that value is not a class value, but the DIVs id value?

$('id[class$="RootAspMenu"]') didn't return the object.  I did see that the above works with classes.
0
 
LVL 60

Assisted Solution

by:Julian Hansen
Julian Hansen earned 1000 total points
ID: 41812637
$('div[id$="RootAspMenu"]')

Open in new window

0
 
LVL 1

Author Closing Comment

by:Howard Bash
ID: 41812661
Great stuff.  Thanks folks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

927 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