Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change div title using jquery

Tags:

jquery

I have the following code:

<div id="DivPassword" title="test" > 

I want to change the div title and I have the following code:

 function ChangeAttribute() {
         $("#DivPassword")
            .attr('title', 'Photo by Kelly Clark');
         $('#DivPassword').dialog('open');
         return false;
     }

When the dialog is opened, the title is still test! if I don't assign any title to the div, the dialog doesn't show any title. How can I correct that?


 function ChangeAttribute() {
         $("#DivPassword")
            .attr('title', 'Photo by Kelly Clark')
            .dialog('open');

         alert($("#DivPassword").attr('title'));
     }

$('#DivPassword').dialog({
             autoOpen: false,
             width: 800,
             buttons: {
                 "Cancel": function() {
                     $(this).dialog("close");
                 },
                 "Accept": function() {
                 alert($(this).attr('title'));
                     $(this).dialog("close");
                 }
             }
         });

 <script type="text/javascript">
     var Dtitle;
     $(function() {
        $('#DivPassword').dialog({

             autoOpen: false,
             width: 800,
             title : Dtitle,
             buttons: {
                 "Cancel": function() {
                     $(this).dialog("close");
                 },
                 "Accept": function() {
                     $(this).dialog("close");
                 }
             }
         });
     });

     function ChangeAttribute(name) {
         $("#DivPassword")
            .attr('title', name)
            .dialog('open');
         Dtitle = $("#DivPassword").attr('title');
         alert(Dtitle);
     }


</script>
like image 579
learning Avatar asked Apr 23 '10 06:04

learning


People also ask

How to change title of div in jquery?

To set the title property on an element, use: $('#yourElementId'). prop('title', 'your new title');

How do I change dynamic value tooltip?

Drag the calculated field to the appropriate tooltip and you'll see an ATTR dimension pill with a tooltip logo in the Marks card. Insert the ATTR budget and adjusted inflated gross calculated fields into its corresponding tooltip as seen in Image 6. After that, you're dynamic tooltip should work!


2 Answers

You can change the title of a dialog directly with:

$('#DivPassword').dialog('option', 'title', 'Photo by Kelly Clark');

This will work in your case. In fact, your code to change the title attribute is correct. I guess that the dialog plugin creates the dialog when .dialog is called first. The open method just displays the dialog then, without re-creating it from the div.

like image 155
Christian Studer Avatar answered Oct 04 '22 05:10

Christian Studer


You can change ANY attribute from any DOM element with jQuery as easy as:

$("#divMessage").attr('title', 'Type here the new Title text');

Cheers!

like image 42
Jhollman Avatar answered Oct 04 '22 04:10

Jhollman