Reputation: 1101
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
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
Reputation: 5818
Try using this $('#\\#abc')
by escaping any special characters with the id.
$(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