0

I am trying to insert > character to button in jquery. I need a button like this "Continue >".

jQuery("#hello").dialog({
       buttons: {
          Continue&gt: function() {
             jQuery( this ).dialog( "close" );
          }
       }
});

I tried Continue&gt:, Continue>: Continue>:, but with no success. Please help me

Sumanth
  • 595
  • 3
  • 14
  • 39

4 Answers4

4

You have to quote the button name.

See: http://api.jqueryui.com/dialog/#option-buttons

Quick ref:

Specifies which buttons should be displayed on the dialog. The context of the callback is the dialog element; if you need access to the button, it is available as the target of the event object. Multiple types supported: Object: The keys are the button labels and the values are the callbacks for when the associated button is clicked. Array: Each element of the array must be an object defining the attributes, properties, and event handlers to set on the button.

Code:

$("#hello").dialog({
       buttons: {
          "Continue>": function() {
             $( this ).dialog( "close" );
          }
       }
});

Demo: http://jsfiddle.net/cCCMG/1/

Irvin Dominin
  • 30,819
  • 9
  • 77
  • 111
1

You need to quote any property names that are not unreserved identifiers.

jQuery("#hello").dialog({
       buttons: {
          "Continue>": function() {
             jQuery( this ).dialog( "close" );
          }
       }
});
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
  • This is the correct answer. The problem is with general JavaScript syntax, as stated in the answer. There is no need to “escape” the character “>” in a JavaScript string constant, but the string must be written in quotatuon marks. – Jukka K. Korpela Sep 10 '13 at 16:09
0

You can quote the text for the button name but that still won't let you use HTML character entities. You can however do this:

$('.ui-button-text').append(' »');

jsFiddle example

j08691
  • 204,283
  • 31
  • 260
  • 272
  • In addition to being unnecessarily complicated, this approach adds a wrong character (“›” and not “>”), – Jukka K. Korpela Sep 10 '13 at 16:07
  • @JukkaK.Korpela - I used that character simply as an example of a character that doesn't have a simple keyboard replacement like >. And please explain to us all how my one line solution is "unnecessarily complicated". – j08691 Sep 10 '13 at 16:11
  • The question was about “>”, and not even a one-liner fix is needed when the name `'Continue >'` is properly quoted. – Jukka K. Korpela Sep 10 '13 at 16:39
0

For reference, since you mentioned HTML character entities, you can use Octal character codes in your button's text:

HTML

<div id='hello'>hello world</div>

jQuery

$("#hello").dialog({
   buttons: {
     "Continue \273": function() { // Note the escaped '273' (open/close chevron-style quotes)
       $(this).dialog("close");
     }
   }
});

Codepen example

kunalbhat
  • 1,709
  • 10
  • 11
  • Octal escape sequences are non-standard and explicitly disallowed in strict mode. http://es5.github.io/#B.1.2 says "The syntax and semantics of 7.8.4 can be extended as follows except that this extension is not allowed for strict mode code..." – Mike Samuel Sep 10 '13 at 16:40