I have a modal dialog and I want to change some of its properties through javascript. I have found the jquery code


but when I try to use the javascript


it comes back null. I am not sure whether I am converting jquery to javascript wrong or I have the wrong id.

I am using Sharepoint 2010.

1 Answer 1


The id of the close button is not just "DlgClose" it is "DlgClose< GUID >". For example, DlgClose355aef3c-ef2f-4293-a7b1-ffa236195624

In your jQuery code, you are using a begins-with selector ^ which gets all elements whose id starts with a particular string. (DlgClose in this case.)

While in your JavaScript code, you are getting all the elements whose id is exactly "DlgClose". document.getElementById checks for that exact id and gets elements if any. That is why you are getting a null value.

I would suggest you stick to jQuery as it will really make life easier for you. But still if you want to perform the same functionality with pure JavaScript, then have a look here: https://stackoverflow.com/questions/10111668/find-all-elements-whose-id-begins-with-a-common-string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.