Solved

jQuery Selector Question

Posted on 2016-09-22
7
68 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 250 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 58

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 58

Assisted Solution

by:Julian Hansen
Julian Hansen earned 250 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Suggested Courses

615 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