code_junkie

How to compare html entity with JQuery

Nov 10th, 2011
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <h3 id="headerid"><span onclick="expandCollapse('headerid')">&uArr;</span>Header title</h3>
  2.  
  3. function expandCollapse(id) {
  4. var arrow = $("#"+id+" span").html(); // I have tried with .text() too
  5. if(arrow == "&dArr;") {
  6. $("#"+id+" span").html("&uArr;");
  7. } else {
  8. $("#"+id+" span").html("&dArr;");
  9. }
  10. }
  11.  
  12. function expandCollapse(id) {
  13. var arrow = $("#"+id+" span").html();
  14. if(arrow == "u21d1") {
  15. $("#"+id+" span").html("u21d3");
  16. } else {
  17. $("#"+id+" span").html("u21d1");
  18. }
  19. }
  20.  
  21. <div id="inplace">
  22. <div id="myStatic">Hello World!</div>
  23. <div id="myEdit" style="display: none">
  24. <input id="myNewTxt" type="text" />
  25. <input id="myOk" type="button" value="OK" />
  26. <input id="myX" type="button" value="X" />
  27. </div></div>
  28.  
  29. $("#myStatic").bind("click", function(){
  30. $("#myNewTxt").val($("#myStatic").text());
  31. $("#myStatic,#myEdit").toggle();
  32. });
  33. $("#myOk").click(function(){
  34. $("#myStatic").text($("#myNewTxt").val());
  35. $("#myStatic,#myEdit").toggle();
  36. });
  37. $("#myX").click(function(){
  38. $("#myStatic,#myEdit").toggle();
  39. });
  40.  
  41. <h3 id="headerId"><span class="upArrow">&uArr;</span>Header title</h3>
  42.  
  43. $( '.upArrow, .downArrow' ).click( function( span ) {
  44. if ( span.hasClass( 'upArrow' ) )
  45. span.text( "&dArr;" );
  46. else
  47. span.text( "&uArr;" );
  48. span.toggleClass( 'upArrow' );
  49. span.toggleClass( 'downArrow' );
  50. } );
Add Comment
Please, Sign In to add comment