Jerlam
Jerlam

Reputation: 1101

Read id starting with # in jquery

I am scraping a web page, and the div that I need to access has id="#abc". I am using cheerio to scrape the page, so I need to do it in JQuery but it does not work:

$('##abc') // undefined

But it works with pure javascript:

getElementById("#abc") // works well

Upvotes: 1

Views: 227

Answers (3)

ASalameh
ASalameh

Reputation: 803

You can try this for input(hidden,text..)

$("[id='#abc']").val()

As @Scott Marcus Suggested

This for all non-form field elements:

$("[id='#abc']").html()
$("[id='#abc']").text()

Upvotes: 1

Hary
Hary

Reputation: 5818

Try using this $('#\\#abc') by escaping any special characters with the id.

Check here

$(function()
{
 var a  = document.getElementById("#abc")
 
 
 var b  = $('#\\#abc')
 
 $(b).val("test")
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="#abc" />

Upvotes: 3

saturnusringar
saturnusringar

Reputation: 169

Give this a try:

$('[id="#abc"]');

Upvotes: 1

Related Questions