1

I am having troubles using JQuery to select the correct element. Using javascript DOM is working fine, but with JQuery I can not seem to get the correct element...

This is working fine (the 'medium' length is 1, the 'small' length is 0) :

var medium = document.getElementById("Ribbon.Documents.WorkflowButtons.Workflow" + button + "-Medium");
var small = document.getElementById("Ribbon.Documents.WorkflowButtons.Workflow" + button + "-Small");

alert("Medium: " + jQuery(medium).length + " - Small: " + jQuery(small).length + " - State: " + workflowButtonState);

While this is not working (both lengths are equal to 0, which is not correct):

var medium = jQuery("#Ribbon.Documents.WorkflowButtons.Workflow" + button + "-Medium");
var small = jQuery("#Ribbon.Documents.WorkflowButtons.Workflow" + button + "-Small");

alert("Medium: " + jQuery(medium).length + " - Small: " + jQuery(small).length + " - State: " + workflowButtonState);

Another not working example is when using .html()

Working (returns the html):

var button = document.getElementById("Ribbon.Documents.WorkflowButtons.Workflow" + buttonId + "-" + state);
$(button).css("display", "none");
alert($(button).html());

Not working (.html() return NULL)

var button = $("#Ribbon.Documents.WorkflowButtons.Workflow" + buttonId + "-" + state);
$(button).css("display", "none");
alert($(button).html());

Any idea why this is happening? I am executing this on the same page. So the same HTML elements etc. results should be the same, no ?

I have verified the "document.readyState" being equal to "complete"

PS: I have used two syntaxes: jQuery and $. This was to make sure there were no other issues.

Thanks !

Frederik Prijck
  • 1,424
  • 10
  • 16

1 Answers1

1

Periods have a special meaning in jQuery. So you need to escape them with a slash. Unfortunately, the slash is also the escape character for Javascript strings, so you have to use double-slashes:

jQuery("#Ribbon\\.Documents\\.WorkflowButtons\\.Workflow" + button + "-Medium");
Philipp
  • 67,764
  • 9
  • 118
  • 153