Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

jQuery("a[id^='DlgClose']")

but when I try to use the javascript

document.getElementById("DlgClose")

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.

share|improve this question

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: http://stackoverflow.com/questions/10111668/find-all-elements-whose-id-begins-with-a-common-string

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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