0

First time posting = ) I have been searching for a little while and have tried many ('refresh').trigger , ('create') and markup answers other members have suggested or I have seen on other posts. I am pretty new to JS JQM but I am having troubles having my dynamically added buttons viewed with the CSS properties. I have tried other solutions posted on similar questions such as: How to add dynamic jquery button? Jquery Dynamically generated buttons no css A few other posts too.

Sorry in advance if already answered, I could not find a solution.

Here is my code: The Reason I made the button a variable was because of another form post suggested it then refreshing that way...

$( '#csvButton' ).on( 'click', function() {
    $('#viewData').empty();
    $('#testView').empty();
        $.ajax( {
            url: 'xhr/data.csv',
            type: 'GET',
            dataType: 'text',
            success:function ( result ) {
            //console.log(result);
            var lines = result.split("\n");
            //console.log(lines);
            var dataRow = lines[0];
            var dataCol = dataRow.split(",");
            for (var lineNum = 1; lineNum < lines.length; lineNum++) {
                var row = lines[lineNum];
                var columns = row.split(",");
                    var thisButton = $("<a>").attr("href", "#").attr("data-role", "button").attr("data-theme", columns[1]).attr("data-icon", columns[2]).text(columns[0]);
                thisButton.appendTo('#testView');
                $('<ul>' + '<li><b>' + dataCol[0] + " " + columns[0] + '</b></li>' +
                    '<li>'+ dataCol[1] + " " + columns[1] + '</li>' +
                    '<li>'+ dataCol[2] + " " + columns[2] + '</li>' + '</ul>'
                ).appendTo('#testView');
        }   
            }
        });
    });
return false;
});

I am having trouble with thisButton displaying properly with CSS properties. I am made it a link with data-role="button" and trying it as a my CSV has button name "Settings", button theme "a", and button icon "gear" data. Any help would be great. #testView was a temp I created to test ideas to get CSS properties to work.

Thanks in advance!

2 Answers 2

0

Well you're working on dynamic buttons so it seems it would be better if you set css to a class and then add class to button dynamicaly. Try add class to your css code with parameters you need and then in your code put somewhere

$("#testView").addClass("name of your class");

I'm sorry but i can test this solution right away so i'm not sure if its working as you wish. Good Luck :)

Sign up to request clarification or add additional context in comments.

Comments

0

You can remove or put CSS properties with this:

E.g.:

 $("#testView").class('display', 'none');

Look at this Porperty CSS documentation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.